grammer.z80 69 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510
  1. ;Grammer
  2. ;================:
  3. ;\\ /\ :
  4. ; \\ //\\ :
  5. ; \\ // \\ :
  6. ; \\/----\\ :
  7. ; //\----//\ :
  8. ; // \\ // \\ :
  9. ; // \\// \\ :
  10. ;// \/ \\:
  11. ;================:
  12. ;Project.........Grammer
  13. ;Program.........Grammer
  14. ;Author..........Zeda Thomas (Xeda112358 / ThunderBolt)
  15. ;[email protected]
  16. ;Size............
  17. ;Language........English
  18. ;Programming.....Assembly
  19. ;Version.........v2.50 ;I rarely update this stuff
  20. ;Last Update.....27 Nov 2019 ;This is not accurate, probably
  21. #define NO_JUMP_TABLE
  22. #include "grammer2.5.inc"
  23. #include "grammer.inc"
  24. #define Coord(y,x) .db 01,y,x
  25. #define SHELL_BROKEN
  26. #define speed
  27. #define K_DELAY_DEFAULT 13
  28. #define K_DELAY_ACCEL 3
  29. #define ALIGN_COMMAND_TABLE ;Comment this to potentially save some bytes, uncomment to save some clock cycles
  30. #define include_fire
  31. #define include_ncr
  32. ;#define include_LoadTSA
  33. ;#define include_interrupt
  34. #define INCLUDE_GRAMPKG
  35. #define INDEX_VFONT ;Allows faster font access for key portions of the font
  36. .org $4000
  37. .db $80,$0F, 0,0,0,0
  38. .db $80,$12, $01,$04 ;signing key ID
  39. .db $80,$47, "Grammer" ;change the $47 according to name len.
  40. .db $80,$81, 2 ;num pages
  41. .db $80,$90 ;no splash
  42. .db $03,$22,$09,$00 ;date stamp
  43. .db $02,$00 ;date stamp signature
  44. .db $80,$70 ;final field
  45. jp main
  46. jumptable:
  47. #include "jmptable.z80"
  48. SelectedProg:
  49. bcall(_OP5ToOP1)
  50. ; ld de,OP1
  51. ; ld hl,OP5
  52. ; call mov9
  53. SelectedProgOP1:
  54. ld hl,gbuf
  55. ld (BufPtr),hl
  56. bcall(_ChkFindSym)
  57. ret c
  58. ld hl,cmdShadow+2
  59. ld a,$BB
  60. cp (hl)
  61. jr nz,+_
  62. inc l
  63. ld a,$6D
  64. cp (hl)
  65. jp z,EndHook_prepush
  66. _:
  67. ld a,(TempWord3)
  68. or a
  69. jr z,ExecOP1
  70. ;Here we need to move the code to RAM.
  71. ; We will perform some minor pre-compiling
  72. ; Currently it is just:
  73. ; Convert numbers to raw binary
  74. #include "precompile.z80"
  75. jr ExecOP1
  76. ProgramAccessStart:
  77. bcall(_RclAns)
  78. sub 4
  79. jr nz,begin_parse
  80. ex de,hl
  81. ld c,(hl)
  82. inc hl
  83. ld b,(hl)
  84. inc hl
  85. ld de,OP1
  86. ldir
  87. ld (de),a
  88. ExecOP1:
  89. ld hl,OP1
  90. ld de,basic_prog
  91. call mov9
  92. bcall(_ChkFindSym)
  93. ld a,b
  94. ret c
  95. or a \ ret nz
  96. ex de,hl
  97. ld c,(hl)
  98. inc hl
  99. ld b,(hl)
  100. inc hl
  101. parse_via_ptr:
  102. ;HL points to code
  103. ;BC is the size
  104. ld (parsePtr),hl
  105. ld (progStart),hl
  106. add hl,bc
  107. ld (progEnd),hl
  108. ld h,a \ ld l,a
  109. ld (parseError),hl
  110. begin_parse:
  111. #ifdef include_interrupt
  112. di
  113. ld a,11
  114. out (3),a
  115. ld a,6
  116. out (4),a ;set slowest hardware timer mode
  117. ld a,41h
  118. ld i,a
  119. im 2
  120. ei
  121. #endif
  122. call SetUpData
  123. ; call progmeta
  124. ld hl,BreakProgram
  125. push hl
  126. ParserNext:
  127. ld de,ParserNext
  128. push de
  129. ParseArg:
  130. bit IntActiveFlag,(iy+InternalFlag)
  131. call z,parser_interrupt
  132. bit OnBlockFlag,(iy+UserFlags)
  133. call z,onbreak
  134. ld hl,(parsePtr)
  135. ParseArg2:
  136. ld a,(hl)
  137. inc hl
  138. ld (parsePtr),hl
  139. #ifdef ALIGN_COMMAND_TABLE
  140. ld h,CommandJumpTable>>8
  141. add a,a
  142. ld l,a
  143. jr nc,+_
  144. inc h
  145. _:
  146. rra
  147. ld e,(hl)
  148. inc l
  149. #else
  150. ld e,a
  151. ld hl,CommandJumpTable
  152. ld d,0
  153. add hl,de
  154. add hl,de
  155. ld e,(hl)
  156. inc hl
  157. #endif
  158. ld d,(hl)
  159. push de
  160. ld hl,(parsePtr)
  161. ret
  162. OutputToken:
  163. ld a,(hl)
  164. cp 11
  165. jr nz,+_
  166. call ParseNextFullArg
  167. ld a,c
  168. ld (OutputLogic),a
  169. ret
  170. _:
  171. call ParseFullArg
  172. ld hl,textmode
  173. ld (hl),c
  174. ld e,a
  175. ld a,c
  176. #ifdef INDEX_VFONT
  177. push af
  178. #endif
  179. ld bc,FontSet
  180. or a
  181. jr z,+_
  182. ld bc,vFont
  183. dec a
  184. jr z,+_
  185. ld bc,FontSet
  186. dec a
  187. jr z,+_
  188. dec a
  189. ld c,a
  190. ;this part is based on E37's fasttext routine
  191. push de
  192. ld a,(iy+hookflags3) ;Need to disable font hooks flag while we
  193. push af ;try to locate the font data, or we might
  194. res fontHookActive,(iy+hookflags3) ;get a pointer to the custom font table.
  195. dec c
  196. call z,sfont_ptr
  197. call nz,lfont_ptr
  198. pop af
  199. ld (iy+hookflags3),a
  200. ld b,d
  201. ld c,e
  202. pop de
  203. _:
  204. ld a,e
  205. cp 2Bh
  206. call z,ParseNextFullArg
  207. ld (FontPointer),bc
  208. ld c,0
  209. cp $2B
  210. call z,ParseNextFullArg
  211. ld a,c
  212. ld (font_ptr_page),a
  213. #ifdef INDEX_VFONT
  214. pop af
  215. dec a
  216. ret nz
  217. ;need to find chars 32, 48, 64, and 96
  218. ld hl,(FontPointer)
  219. ;HL points to the font
  220. ;The first byte is the height of the font
  221. ld e,(hl)
  222. ld d,0
  223. inc hl
  224. ld b,33
  225. call lookupchar_vfont
  226. ld (vfont_index),hl
  227. ld b,17
  228. call lookupchar_vfont
  229. ld (vfont_index+2),hl
  230. ld b,17
  231. call lookupchar_vfont
  232. ld (vfont_index+4),hl
  233. ld b,33
  234. call lookupchar_vfont
  235. ld (vfont_index+6),hl
  236. ld bc,(FontPointer)
  237. ret
  238. vputc_loc_loop:
  239. ld a,(hl)
  240. inc hl
  241. dec a
  242. jp m,vputc_loc_loop_end
  243. _:
  244. add hl,de
  245. sub 8
  246. jr nc,-_
  247. vputc_loc_loop_end:
  248. lookupchar_vfont:
  249. ;DE is the height
  250. ;HL points to the font data
  251. ;B is the char+1
  252. djnz vputc_loc_loop
  253. #endif
  254. ret
  255. sfont_ptr:
  256. bcall(_SFont_Len)
  257. xor a
  258. ret
  259. lfont_ptr:
  260. ld hl,$6D81
  261. call is_start_lfont
  262. ret z
  263. ld hl,$7184
  264. call is_start_lfont
  265. ret z
  266. jp err_fatal
  267. is_start_lfont:
  268. push hl
  269. ld de,lFont_record
  270. ld a,$7F ;bootcode
  271. ld bc,3
  272. call readarc
  273. pop de
  274. ld hl,lFont_record
  275. ld a,(hl)
  276. sub 5
  277. ret nz
  278. inc hl
  279. or (hl)
  280. ret nz
  281. inc hl
  282. or (hl)
  283. ret
  284. NewLine:
  285. ld hl,(BufPtr)
  286. ld (gbuf_temp),hl
  287. ld (Ans),bc
  288. IncPtr:
  289. _Ret:
  290. ret
  291. augment:
  292. call ParseFullArg
  293. ld h,b \ ld l,c
  294. bcall(_EnoughMem)
  295. jp c,ErrMem
  296. push de
  297. call ParseNextFullArg
  298. push bc
  299. ld hl,(parsePtr)
  300. inc hl
  301. ld (parsePtr),hl
  302. call GetVarInfo
  303. jp c,Pop2Exit
  304. or a \ jp nz,Pop2Exit
  305. ld hl,(parsePtr)
  306. ld (parsePtr),hl
  307. ex de,hl
  308. ld c,(hl) \ inc hl
  309. ld b,(hl)
  310. ld (TempWord1),hl
  311. pop de \ pop hl
  312. InsertData:
  313. push hl
  314. add hl,bc
  315. ld b,h \ ld c,l
  316. ld hl,(TempWord1)
  317. ld (hl),b \ dec hl
  318. ld (hl),c \ inc hl \ inc hl
  319. add hl,de
  320. pop de
  321. ;hl points to where to insert data
  322. ;de is the number of bytes to insert
  323. push de \ push hl
  324. ld a,h \ or l
  325. jr z,+_
  326. ex de,hl
  327. bcall(_InsertMem)
  328. _:
  329. ld hl,(parsePtr)
  330. ld (parsePtr),hl
  331. pop hl \ pop bc
  332. ld d,h \ ld e,l
  333. ZeroMem:
  334. ld a,b \ or c \ ld a,0
  335. push de
  336. call nz,SetMem
  337. pop bc
  338. ret
  339. _:
  340. ld hl,tilemap_new
  341. ld (next_page_call_address),hl
  342. jp next_page_call
  343. PtChange:
  344. call ParseFullArg ;To get the tilemap routine correct
  345. ld a,c
  346. or a
  347. jr nz,-_
  348. call ParseNextFullArg ;Map Data
  349. push bc
  350. call ParseNextFullArg ;Tile Data
  351. push bc
  352. call ParseNextFullArg ;MapWidth
  353. push bc
  354. call ParseNextFullArg ;MapX offset
  355. ld (TempWord2),bc
  356. call ParseNextFullArg ;MapY offset
  357. ld (TempWord3),bc
  358. call ParseNextFullArg ;Sprite Method
  359. push bc
  360. cp 2Bh
  361. call z,ParseNextFullArg_Buffer
  362. pop bc
  363. ld a,c
  364. pop hl
  365. pop bc
  366. pop de
  367. jp TileMap1
  368. solveSet:
  369. call ParseFullArg
  370. ld a,c
  371. sub 3
  372. jr z,ErrorHandle
  373. dec a
  374. jr z,CallError
  375. ld hl,solveSet_p1
  376. ld (next_page_call_address),hl
  377. jp next_page_call
  378. _:
  379. ErrorHandle:
  380. call ParseNextFullArg
  381. ld (ParseError),bc
  382. ret
  383. CallError:
  384. call ParseNextFullArg
  385. ld a,c
  386. cp 2
  387. jr nz,HandleError
  388. call ParseNextFullArg
  389. ld h,b \ ld l,c
  390. call GetGrammerText
  391. ld hl,13
  392. or a
  393. sbc hl,bc
  394. jr nc,+_
  395. CustomError:
  396. ld bc,12
  397. _:
  398. ex de,hl
  399. ld de,appErr1
  400. ldir
  401. xor a
  402. ld (de),a
  403. ld a,2
  404. HandleError:
  405. jp GramHandl
  406. DSToken:
  407. ld a,(hl) \ inc hl
  408. call VarP
  409. ret nc
  410. ld (parsePtr),de
  411. ld e,(hl) \ inc hl \ ld d,(hl)
  412. ld a,(de) \ ld c,a
  413. dec de \ ld (hl),d \ dec hl \ ld (hl),e
  414. ld b,0 \ ret
  415. ISToken:
  416. ld a,(hl) \ inc hl
  417. call VarP
  418. ret nc
  419. ld (parsePtr),de
  420. g_ReadByte:
  421. ld e,(hl) \ inc (hl) \ inc hl \ ld d,(hl)
  422. jr nz,+_
  423. inc (hl)
  424. _:
  425. ex de,hl
  426. ld c,(hl)
  427. ld b,0
  428. dec de
  429. ex de,hl
  430. ret
  431. AnsToken:
  432. ld bc,(Ans) \ ret
  433. seqToken:
  434. CopyHex:
  435. ex de,hl
  436. ld h,b \ ld l,c
  437. _:
  438. call PutHexFromDE
  439. jr z,+_
  440. call PutHexFromDE
  441. inc hl
  442. jr nz,-_
  443. dec hl
  444. xor a
  445. rld
  446. _:
  447. ld (parsePtr),de
  448. ld b,h \ ld c,l
  449. ret
  450. PutHexFromDE:
  451. inc de
  452. ld a,(de)
  453. cp 3Fh
  454. ret z
  455. cp 3Ah
  456. jr c,+_
  457. sub 7
  458. _:
  459. rld
  460. ret
  461. SetData:
  462. ;[
  463. ld a,(hl)
  464. cp 16
  465. jr z,CopyHex ;[(
  466. cp 6
  467. jr z,+_ ;[[
  468. dec hl
  469. ld (parsePtr),hl
  470. scf
  471. _:
  472. sbc a,a
  473. ld e,a
  474. ld h,b \ ld l,c
  475. SetData_loop:
  476. push hl
  477. push de
  478. call ParseNextFullArg
  479. pop de
  480. rlc e
  481. jr nc,+_
  482. dec hl
  483. ld a,(hl)
  484. cp 11
  485. inc hl
  486. _:
  487. ld a,(hl)
  488. pop hl
  489. ld (hl),c \ inc hl
  490. jr nz,+_
  491. ld (hl),b \ inc hl
  492. _:
  493. cp 2Bh
  494. jr z,SetData_loop
  495. ld b,h
  496. ld c,l
  497. ret
  498. VarName:
  499. ld e,a
  500. ld d,(hl)
  501. inc d
  502. call GetNextVarNum
  503. dec d
  504. ld (parsePtr),hl
  505. ld (OP1+1),de
  506. xor a
  507. ld (OP1+3),a
  508. rst rFindSym
  509. jp VarTokenStepIn
  510. FuncToken:
  511. call ParseFullArg
  512. ld (IntLoc),bc
  513. ld bc,80h
  514. cp 2Bh
  515. call z,ParseNextFullArg
  516. dec bc \ inc b \ inc c
  517. ld (IntMax),bc
  518. ld (IntCount),bc
  519. ret
  520. SendToken:
  521. ld a,(hl)
  522. cp $AE
  523. jr nz,NotSendByte
  524. ;timer,byte
  525. ;success or fail
  526. call ParseNextFullArg
  527. push bc
  528. call ParseNextFullArg
  529. pop de
  530. #include "subroutines/sendbyte.z80"
  531. NotSendByte:
  532. call ParseFullArg
  533. push bc ;Size of the var
  534. inc hl \ ld (parsePtr),hl
  535. call GetVarName
  536. ex de,hl
  537. ld de,OP1
  538. ldir
  539. xor a
  540. ld (de),a
  541. bcall(_ChkFindSym)
  542. pop hl
  543. jr nc,+_
  544. ld a,(OP1)
  545. and 1fh
  546. bcall(_EnoughMem)
  547. jp c,ErrMEM
  548. ex de,hl
  549. bcall(_CreateVar)
  550. ex de,hl
  551. ld a,b
  552. or c
  553. inc hl
  554. inc hl
  555. push hl
  556. call nz,ZeroMem
  557. pop bc
  558. ret
  559. _:
  560. inc de \ inc de
  561. ld c,e \ ld b,d
  562. ret
  563. FixToken:
  564. ld a,(hl)
  565. cp 93h
  566. jr nz,SetMode
  567. call ParseNextFullArg
  568. ld a,c
  569. ld (TextPauseTime),a
  570. ret
  571. SetMode:
  572. ld a,(flags+UserFlags)
  573. ld b,0 ; not needed, per se, but nice for output
  574. ld c,a
  575. call ParseFullArg
  576. ld a,c
  577. ld (flags+UserFlags),a
  578. ret
  579. FloatModeToggle:
  580. ;Toggles float mode.
  581. ;In float mode, operations default to float operations.
  582. ld a,(flags+ModeFlags2)
  583. xor 1<<floatmode
  584. ld (flags+ModeFlags2),a
  585. ret
  586. OSVarToken:
  587. ld a,(hl)
  588. inc hl
  589. ld (parsePtr),hl
  590. ld hl,0
  591. ld (OP1+2),hl
  592. ld (OP1+1),a
  593. rst rFindSym
  594. jr c,return_BC_0
  595. ex de,hl
  596. call convFloat
  597. ld b,d \ ld c,e
  598. ret
  599. return_BC_0:
  600. ld bc,0
  601. ret
  602. TangentToken:
  603. call ParseFullArg
  604. xor a \ ld b,a
  605. or c
  606. ret z
  607. push bc
  608. call ParseNextFullArg
  609. ld a,c
  610. pop bc
  611. or a \ ret z
  612. push af
  613. push bc
  614. ld a,(hl)
  615. cp 2Bh
  616. ld bc,(BufPtr)
  617. call z,ParseNextFullArg
  618. ld (TempWord1),bc
  619. pop bc
  620. pop af
  621. ShiftGraphBuf:
  622. ld b,4
  623. push bc
  624. rrca
  625. push af
  626. ld a,c
  627. call c,ShiftGraphDownA
  628. pop af
  629. pop bc
  630. push bc
  631. rrca
  632. push af
  633. ld a,c
  634. call c,ShiftGraphLeftA
  635. pop af
  636. pop bc
  637. push bc
  638. rrca
  639. push af
  640. ld a,c
  641. call c,ShiftGraphRightA
  642. pop af
  643. pop bc
  644. rrca
  645. ld a,c
  646. ret nc
  647. ShiftGraphUpA:
  648. ld e,a
  649. ld l,a
  650. ld h,0
  651. ld d,h
  652. add hl,hl
  653. add hl,de
  654. add hl,hl
  655. add hl,hl
  656. push hl
  657. ld a,h
  658. inc a
  659. cpl
  660. and 3
  661. ld b,a
  662. ld a,l
  663. dec a
  664. cpl
  665. ld c,a
  666. ld de,(TempWord1)
  667. add hl,de
  668. ldir
  669. pop bc
  670. ZeroMemF:
  671. xor a
  672. SetMemF:
  673. ld (de),a
  674. ld h,d \ ld l,e
  675. inc de
  676. ReadRAM:
  677. ldir
  678. ret
  679. ShiftGraphRightA:
  680. rrca
  681. push af
  682. call c,ShiftRight1
  683. pop af
  684. rrca
  685. push af
  686. call c,ShiftRight2
  687. pop af
  688. rrca
  689. push af
  690. call c,ShiftRight4
  691. pop af
  692. rrca
  693. push af
  694. call c,ShiftRight8
  695. pop af
  696. rrca
  697. push af
  698. call c,ShiftRight16
  699. pop af
  700. rrca
  701. push af
  702. call c,ShiftRight32
  703. pop af
  704. rrca
  705. ret nc
  706. ShiftRight64:
  707. ld hl,(TempWord1)
  708. ld a,l
  709. sub 9
  710. jr nc,+_
  711. dec h
  712. _:
  713. ld l,a
  714. ld a,4
  715. jr ShiftRight8OrMore
  716. ShiftRight32:
  717. ld hl,(TempWord1)
  718. ld a,l
  719. sub 5
  720. jr nc,+_
  721. dec h
  722. _:
  723. ld l,a
  724. ld a,8
  725. jr ShiftRight8OrMore
  726. ShiftRight16:
  727. ld hl,(TempWord1)
  728. dec hl \ dec hl \ dec hl
  729. ld a,10
  730. ShiftRight8OrMore:
  731. inc h
  732. inc h
  733. inc h
  734. ld b,0
  735. ld c,a
  736. ld (TempWord3),bc
  737. sub 13
  738. cpl
  739. ld (TempWord2+1),a
  740. ld b,64
  741. ld de,(TempWord1)
  742. inc d \ inc d \ inc d
  743. dec de
  744. SR8OMLoop:
  745. ;TempWord2==number of bytes to clear
  746. ;TempWord3==number of bytes to shift
  747. ;b=64
  748. push bc
  749. ld bc,(TempWord3)
  750. lddr
  751. ld bc,(TempWord2)
  752. xor a
  753. _:
  754. ld (de),a
  755. dec de
  756. dec hl
  757. djnz -_
  758. pop bc
  759. djnz SR8OMLoop
  760. ret
  761. ShiftRight8:
  762. ld hl,(TempWord1)
  763. ld d,64
  764. ShiftRight8_loop:
  765. xor a
  766. ld b,12
  767. _:
  768. ld c,(hl)
  769. ld (hl),a
  770. inc hl
  771. ld a,c
  772. djnz -_
  773. dec d
  774. jr nz,ShiftRight8_loop
  775. ret
  776. ShiftRight2:
  777. call ShiftRight1
  778. ShiftRight1:
  779. ld hl,(TempWord1)
  780. ld c,64
  781. ShiftRight1_loop:
  782. xor a
  783. ld b,12
  784. _:
  785. rr (hl)
  786. inc hl
  787. djnz -_
  788. dec c
  789. jr nz,ShiftRight1_loop
  790. ret
  791. ShiftRight4:
  792. ld hl,(TempWord1)
  793. ld c,64
  794. ShiftRight4_loop:
  795. xor a
  796. ld b,12
  797. _:
  798. rrd
  799. inc hl
  800. djnz -_
  801. dec c
  802. jr nz,ShiftRight4_loop
  803. ret
  804. ShiftGraphLeftA:
  805. rrca
  806. push af
  807. call c,ShiftLeft1
  808. pop af
  809. rrca
  810. push af
  811. call c,ShiftLeft2
  812. pop af
  813. rrca
  814. push af
  815. call c,ShiftLeft4
  816. pop af
  817. rrca
  818. push af
  819. call c,ShiftLeft8
  820. pop af
  821. rrca
  822. push af
  823. call c,ShiftLeft16
  824. pop af
  825. rrca
  826. push af
  827. call c,ShiftLeft32
  828. pop af
  829. rrca
  830. ret nc
  831. ShiftLeft64:
  832. ld hl,(TempWord1)
  833. ld a,8
  834. add a,l
  835. jr c,+_
  836. inc hl
  837. _:
  838. ld l,a
  839. ld a,4
  840. jr ShiftLeft8OrMore
  841. ShiftLeft32:
  842. ld hl,(TempWord1)
  843. inc hl \ inc hl
  844. inc hl \ inc hl
  845. ld a,8
  846. jr ShiftLeft8OrMore
  847. ShiftLeft16:
  848. ld hl,(TempWord1)
  849. inc hl \ inc hl
  850. ld a,10
  851. ShiftLeft8OrMore:
  852. ld b,0
  853. ld c,a
  854. ld (TempWord3),bc
  855. sub 13
  856. cpl
  857. ld (TempWord2+1),a
  858. ld b,64
  859. ld de,(TempWord1)
  860. SL8OMLoop:
  861. push bc
  862. ld bc,(TempWord3)
  863. ldir
  864. ld bc,(TempWord2)
  865. xor a
  866. _:
  867. ld (de),a
  868. inc de
  869. inc hl
  870. djnz -_
  871. pop bc
  872. djnz SL8OMLoop
  873. ret
  874. ShiftLeft8:
  875. ld hl,(TempWord1)
  876. inc h \ inc h \ inc h
  877. dec hl
  878. ld d,64
  879. ShiftLeft8_loop:
  880. xor a
  881. ld b,12
  882. _:
  883. ld c,(hl)
  884. ld (hl),a
  885. dec hl
  886. ld a,c
  887. djnz -_
  888. dec d
  889. jr nz,ShiftLeft8_loop
  890. ret
  891. ShiftLeft2:
  892. call ShiftLeft1
  893. ShiftLeft1:
  894. ld hl,(TempWord1)
  895. inc h
  896. inc h
  897. inc h
  898. dec hl
  899. ld c,64
  900. ShiftLeft1_loop:
  901. xor a
  902. ld b,12
  903. _:
  904. rl (hl)
  905. dec hl
  906. djnz -_
  907. dec c
  908. jr nz,ShiftLeft1_loop
  909. ret
  910. ShiftLeft4:
  911. ld hl,(TempWord1)
  912. inc h \ inc h \ inc h
  913. dec hl
  914. ld c,64
  915. ShiftLeft4_loop:
  916. xor a
  917. ld b,12
  918. _:
  919. rld
  920. dec hl
  921. djnz -_
  922. dec c
  923. jr nz,ShiftLeft4_loop
  924. ret
  925. ShiftGraphDownA:
  926. ld e,a
  927. ld l,a
  928. ld h,0
  929. ld d,h
  930. add hl,hl
  931. add hl,de
  932. add hl,hl
  933. add hl,hl
  934. push hl
  935. ld a,h
  936. inc a
  937. cpl
  938. and 3
  939. ld b,a
  940. ld a,l
  941. dec a
  942. cpl
  943. ld c,a
  944. ld hl,(TempWord1)
  945. dec hl
  946. add hl,bc
  947. ld de,(TempWord1)
  948. inc d \ inc d \ inc d
  949. dec de
  950. lddr
  951. pop bc
  952. ZeroMemE:
  953. xor a
  954. SetMemE:
  955. ld (de),a
  956. ld h,d \ ld l,e
  957. dec de
  958. lddr
  959. ret
  960. PiToken:
  961. ; Check if the next char is a hex digit. If yes, convert as hexadecimal, else return the float value for pi
  962. ld a,(hl)
  963. sub '0'
  964. sub 10
  965. jr c,ConvHexStr
  966. sub 7
  967. sub 6
  968. jr nc,floatpi
  969. ConvHexStr:
  970. xor a
  971. ex de,hl
  972. ld h,a
  973. ld l,a
  974. _:
  975. add hl,hl
  976. add hl,hl
  977. add hl,hl
  978. add hl,hl
  979. or l
  980. ld l,a
  981. call IsHexTok
  982. jr nc,-_
  983. _:
  984. dec de
  985. ld (parsePtr),de
  986. ld b,h \ ld c,l
  987. ex de,hl
  988. ret
  989. floatpi:
  990. call floatstackpush
  991. push hl
  992. ld de,float_pi
  993. ex de,hl
  994. call mov4_page0
  995. pop bc
  996. ret
  997. #ifdef include_ncr
  998. #include "cmd/ncr.z80"
  999. #endif
  1000. ForToken:
  1001. ld a,(hl)
  1002. inc hl
  1003. push bc
  1004. call VarP
  1005. jr c,+_
  1006. for_constant:
  1007. ;Save ForBackUp for nesting
  1008. ld hl,(ForBackUp)
  1009. ex (sp),hl
  1010. ld bc,for_const_ret
  1011. push bc
  1012. push hl
  1013. ld hl,ForBackUp
  1014. push hl
  1015. xor a
  1016. ld (hl),a
  1017. inc l
  1018. ld (hl),a
  1019. call ParseFullArg
  1020. dec bc
  1021. jr preStartForLoop
  1022. for_const_ret:
  1023. pop hl
  1024. ld (ForBackUp),hl
  1025. ret
  1026. _:
  1027. ld a,(de)
  1028. cp $2B
  1029. jr nz,for_constant
  1030. ld (parsePtr),de
  1031. push hl
  1032. call ParseNextFullArg
  1033. pop hl
  1034. push hl
  1035. ld (hl),c
  1036. inc hl
  1037. ld (hl),b
  1038. call ParseNextFullArg
  1039. preStartForLoop:
  1040. ld e,c
  1041. ld d,b
  1042. pop hl
  1043. pop bc
  1044. StartForLoop:
  1045. push de ;UpperBound
  1046. push hl ;varPointer
  1047. ld hl,(parsePtr)
  1048. push hl ;save parsePtr
  1049. call ParserNext
  1050. pop hl
  1051. ld (TempWord2),hl
  1052. pop hl ;points to var data
  1053. pop de ;upper bound
  1054. ;check DE <= (var)
  1055. ld a,(hl)
  1056. cp e
  1057. inc hl
  1058. ld a,(hl)
  1059. sbc a,d
  1060. ;Now increment
  1061. dec hl
  1062. inc (hl)
  1063. jr nz,+_
  1064. inc hl
  1065. inc (hl)
  1066. _:
  1067. ret nc
  1068. push hl
  1069. ld hl,(TempWord2)
  1070. ld (parsePtr),hl
  1071. pop hl
  1072. jr StartForLoop
  1073. FullToken:
  1074. ld a,(hl)
  1075. ld c,1
  1076. call EndOArg
  1077. call nz,isop
  1078. call nz,ParseFullArg
  1079. SetSpeed:
  1080. in a,(20h)
  1081. ld b,a
  1082. bit 1,c
  1083. jr z,+_
  1084. cpl
  1085. and 1
  1086. ld c,a
  1087. _:
  1088. in a,(2)
  1089. rlca
  1090. and c
  1091. out (20h),a
  1092. ld c,b
  1093. ld b,0
  1094. ret
  1095. ClrDrawToken:
  1096. ld a,(hl)
  1097. call EndOArg
  1098. call nz,isop
  1099. jr z,g_ClrDraw
  1100. call ParseFullArg
  1101. ld h,b \ ld l,c
  1102. ld d,b \ ld e,c
  1103. jp ZeroMem768
  1104. g_ClrDraw:
  1105. ld de,0
  1106. ld (textRow),de
  1107. push bc
  1108. ld hl,(BufPtr)
  1109. pop de
  1110. ZeroMem768:
  1111. xor a
  1112. ld b,a
  1113. ld c,a
  1114. ld (textRow),bc
  1115. ld b,3 ;BC is now 768
  1116. jp SetMem
  1117. ClrHomeToken:
  1118. g_ClrHome:
  1119. ld hl,0
  1120. ld (CurRow),hl
  1121. push bc
  1122. ld b,128
  1123. ld hl,textShadow
  1124. ld a,' '
  1125. call SetSmallMem
  1126. pop bc
  1127. ret
  1128. minToken:
  1129. maxToken:
  1130. push af
  1131. call ParseFullArg
  1132. push bc
  1133. call ParseNextFullArg
  1134. pop hl
  1135. pop af
  1136. g_max:
  1137. or a
  1138. sbc hl,bc
  1139. adc a,0
  1140. rra
  1141. ret nc
  1142. add hl,bc
  1143. ld b,h
  1144. ld c,l
  1145. ret
  1146. factorialToken:
  1147. ld a,(hl)
  1148. call IsConditional \ jr z,+_
  1149. ld de,0 \ push de
  1150. jp factorialStepIn
  1151. _:
  1152. set invlogic,(iy+gflags)
  1153. ret
  1154. FillToken:
  1155. call ParseFullArg
  1156. ld hl,(BufPtr)
  1157. ld a,c
  1158. ld bc,300h
  1159. ld e,-1
  1160. FillBufOR:
  1161. or a \ jr nz,FillBufInv
  1162. _:
  1163. ld a,e \ or (hl) \ ld (hl),a
  1164. cpi
  1165. jp pe,-_
  1166. ret
  1167. FillBufInv:
  1168. dec a \ jr nz,Checker1
  1169. _:
  1170. ld a,e \ xor (hl) \ ld (hl),a
  1171. cpi
  1172. jp pe,-_
  1173. ret
  1174. Checker1:
  1175. dec a \ jr nz,Checker2
  1176. ld a,$AA
  1177. Checker:
  1178. ld c,64
  1179. Checker1_loop:
  1180. ld b,12
  1181. _:
  1182. ld (hl),a
  1183. inc hl
  1184. djnz -_
  1185. cpl \ dec c
  1186. jr nz,Checker1_loop
  1187. ret
  1188. Checker2:
  1189. dec a \ jr nz,LoadBytePatternOR
  1190. ld a,55h \ jr Checker
  1191. LoadBytePatternOR:
  1192. cp 22 \ jr nc,NotArg
  1193. push af \ push bc \ push hl
  1194. call ParseNextFullArg
  1195. ld d,b \ ld e,c \ pop hl \ pop bc \ pop af
  1196. NotArg:
  1197. dec a \ jr z,FillBufOR+3
  1198. LoadBytePatternXOR:
  1199. dec a \ jr z,FillBufInv+3
  1200. LoadBytePatternAND:
  1201. dec a \ jr nz,LoadBytePatternErase
  1202. FillBufAND:
  1203. ld a,e \ and (hl) \ ld (hl),a
  1204. cpi
  1205. jp pe,FillBufAND
  1206. ret
  1207. LoadBytePatternErase:
  1208. dec a \ jr nz,BufCopy
  1209. FillBufErase:
  1210. ld a,e \ cpl \ and (hl) \ ld (hl),a
  1211. cpi
  1212. jp pe,FillBufErase
  1213. ret
  1214. BufCopy:
  1215. dec a \ jr nz,BufOR
  1216. jp mov768
  1217. BufOR:
  1218. dec a \ jr nz,BufAND
  1219. ld a,(de) \ inc de
  1220. or (hl) \ ld (hl),a
  1221. cpi \ jp pe,BufOR+3
  1222. ret
  1223. BufAND:
  1224. dec a \ jr nz,BufXOR
  1225. ld a,(de) \ inc de
  1226. and (hl) \ ld (hl),a
  1227. cpi \ jp pe,BufAND+3
  1228. ret
  1229. BufXOR:
  1230. dec a \ jr nz,BufErase
  1231. _:
  1232. ld a,(de) \ inc de
  1233. xor (hl) \ ld (hl),a
  1234. cpi \ jp pe,-_
  1235. ret
  1236. BufErase:
  1237. dec a \ jr nz,BufSwap
  1238. ld a,(de) \ inc de
  1239. cpl \ and (hl) \ ld (hl),a
  1240. cpi \ jp pe,BufErase+3
  1241. ret
  1242. BufSwap:
  1243. dec a \ jr nz,CopyDown
  1244. ld a,(de)
  1245. push af \ ld a,(hl) \ ld (de),a
  1246. pop af \ ld (hl),a
  1247. inc de
  1248. cpi \ jp pe,BufSwap+3
  1249. ret
  1250. CopyDown:
  1251. ;If Copy Down
  1252. cp 5 \ jr nc,CopyDownOR
  1253. add hl,bc \ dec hl
  1254. push hl
  1255. ld h,d \ ld l,e
  1256. add hl,hl \ add hl,de
  1257. add hl,hl \ add hl,hl
  1258. pop de \ push de \ push hl \ ex de,hl
  1259. sbc hl,de \ ex de,hl
  1260. ld h,b \ ld l,c \ pop bc \ sbc hl,bc
  1261. ld b,h \ ld c,l
  1262. pop hl
  1263. CopyDownOR:
  1264. dec a \ jr nz,CopyDownAND
  1265. _:
  1266. ld a,(de)
  1267. or (hl)
  1268. ld (hl),a
  1269. dec de \ cpd
  1270. jp pe,-_
  1271. ret
  1272. CopyDownAND:
  1273. dec a \ jr nz,CopyDownXOR
  1274. _:
  1275. ld a,(de)
  1276. and (hl)
  1277. ld (hl),a
  1278. dec de \ cpd
  1279. jp pe,-_
  1280. ret
  1281. CopyDownXOR:
  1282. dec a \ jr nz,CopyDownErase
  1283. _:
  1284. ld a,(de)
  1285. xor (hl)
  1286. ld (hl),a
  1287. dec de \ cpd
  1288. jp pe,-_
  1289. ret
  1290. CopyDownErase:
  1291. dec a \ jr nz,CopyUp
  1292. _:
  1293. ld a,(de)
  1294. cpl
  1295. and (hl)
  1296. ld (hl),a
  1297. dec de \ cpd
  1298. jp pe,-_
  1299. ret
  1300. CopyUp:
  1301. ;If Copy Up
  1302. cp 5 \ jr nc,CopyUpOr
  1303. ;de is number of pixels down to copy to
  1304. ;bc is 768
  1305. ;hl points to the buffer
  1306. push hl
  1307. ld h,d \ ld l,e
  1308. add hl,de \ add hl,de
  1309. add hl,hl \ add hl,hl
  1310. ld b,h \ ld c,l
  1311. pop de \ add hl,de
  1312. ;DE points to main buffer
  1313. ;HL points to offset
  1314. push hl
  1315. ld hl,768 \ sbc hl,bc
  1316. ld b,h \ ld c,l
  1317. pop hl
  1318. ex de,hl
  1319. CopyUpOR:
  1320. dec a \ jr nz,CopyUpAND
  1321. _:
  1322. ld a,(de)
  1323. or (hl)
  1324. ld (hl),a
  1325. inc de \ cpi
  1326. jp pe,-_
  1327. ret
  1328. CopyUpAND:
  1329. dec a \ jr nz,CopyUpXOR
  1330. _:
  1331. ld a,(de)
  1332. and (hl)
  1333. ld (hl),a
  1334. inc de \ cpi
  1335. jp pe,-_
  1336. ret
  1337. CopyUpXOR:
  1338. dec a \ jr nz,CopyUpErase
  1339. _:
  1340. ld a,(de)
  1341. xor (hl)
  1342. ld (hl),a
  1343. inc de \ cpi
  1344. jp pe,-_
  1345. ret
  1346. CopyUpErase:
  1347. #ifdef include_fire
  1348. dec a \ jr nz,fire
  1349. #else
  1350. dec a \ ret nz
  1351. #endif
  1352. _:
  1353. ld a,(de)
  1354. cpl
  1355. and (hl)
  1356. ld (hl),a
  1357. inc de \ cpi
  1358. jp pe,-_
  1359. ret
  1360. fire:
  1361. #ifdef include_fire
  1362. #include "cmd/fire.z80"
  1363. #endif
  1364. HorizontalToken:
  1365. call ParseFullArg
  1366. ld a,b \ or a \ ret nz
  1367. ld a,c
  1368. cp 64
  1369. ret nc
  1370. push bc
  1371. ld c,1
  1372. ld a,(hl)
  1373. cp 2Bh
  1374. call z,ParseNextFullArg
  1375. ld d,c
  1376. cp 2Bh
  1377. push de
  1378. ld bc,(BufPtr)
  1379. call z,ParseNextFullArg
  1380. pop de
  1381. pop hl
  1382. push bc
  1383. ld b,h
  1384. ld c,l
  1385. add hl,hl \ add hl,bc
  1386. add hl,hl \ add hl,hl
  1387. ld a,d
  1388. pop bc
  1389. add hl,bc
  1390. ld b,12
  1391. or a
  1392. jr z,SetSmallMem
  1393. dec a
  1394. jr nz,InvertMem
  1395. dec a
  1396. SetSmallMem:
  1397. ld (hl),a
  1398. inc hl
  1399. djnz SetSmallMem
  1400. ret
  1401. InvertMem:
  1402. ld a,(hl)
  1403. cpl
  1404. ld (hl),a
  1405. inc hl
  1406. djnz InvertMem
  1407. ret
  1408. VerticalToken:
  1409. call ParseFullArg
  1410. push bc
  1411. ld c,1
  1412. cp $2B
  1413. call z,ParseNextFullArg
  1414. pop hl
  1415. push bc
  1416. push hl
  1417. cp 2Bh
  1418. call z,ParseNextFullArg_Buffer
  1419. pop bc
  1420. ld b,c
  1421. ld c,0
  1422. call getPixelLoc
  1423. pop bc ;C is the method
  1424. ret nc
  1425. ;it is in-bounds
  1426. ld de,12
  1427. ld b,64
  1428. dec c
  1429. jr nz,draw_vert_toggle
  1430. ld c,a
  1431. _:
  1432. ld a,(hl)
  1433. or c
  1434. ld (hl),a
  1435. add hl,de
  1436. djnz -_
  1437. ret
  1438. draw_vert_toggle:
  1439. dec c
  1440. jr nz,draw_vert_off
  1441. ld c,a
  1442. _:
  1443. ld a,(hl)
  1444. xor c
  1445. ld (hl),a
  1446. add hl,de
  1447. djnz -_
  1448. ret
  1449. draw_vert_off:
  1450. cpl
  1451. ld c,a
  1452. _:
  1453. ld a,(hl)
  1454. and c
  1455. ld (hl),a
  1456. add hl,de
  1457. djnz -_
  1458. ret
  1459. ShadeToken:
  1460. call ParseFullArg
  1461. ld a,c
  1462. add a,$D9
  1463. jr nc,+_
  1464. xor a
  1465. _:
  1466. dec a
  1467. out (16),a
  1468. ret
  1469. StorePicToken:
  1470. call ParseFullArg
  1471. ld b,c
  1472. ld c,60h
  1473. push bc
  1474. cp 2Bh
  1475. ld bc,(BufPtr)
  1476. call z,ParseNextFullArg
  1477. pop hl
  1478. push bc
  1479. ld (OP1+1),hl
  1480. xor a
  1481. ld (OP1+3),a
  1482. rst rFindSym
  1483. jr c,+_
  1484. bcall(_DelVarArc)
  1485. _:
  1486. ld hl,768
  1487. ld a,7
  1488. bcall(_CreateVar) ;_CreatePict only stores 756 bytes.
  1489. inc de
  1490. inc de
  1491. pop hl
  1492. mov768:
  1493. ;14656cc vs 16123cc
  1494. ld bc,768
  1495. _:
  1496. call mov12
  1497. jp pe,-_
  1498. ret
  1499. RecallPicToken:
  1500. call ParseFullArg
  1501. push bc
  1502. cp 2Bh
  1503. ld c,0
  1504. call z,ParseNextFullArg
  1505. ld b,c
  1506. push bc
  1507. ld bc,(BufPtr)
  1508. cp 2Bh
  1509. call z,ParseNextFullArg
  1510. pop af
  1511. ;A is the copy method
  1512. ;{stack} is the pic num
  1513. ld h,b
  1514. ld l,c
  1515. ;42
  1516. ex (sp),hl
  1517. push af
  1518. ld h,0
  1519. ;L is the pic num
  1520. ld (OP1+2),hl
  1521. ld a,$60
  1522. ld (OP1+1),a
  1523. rst rFindSym
  1524. jp c,pop2exit
  1525. ;stack={loc,method}
  1526. ld a,b
  1527. ld b,0
  1528. push af
  1529. call GetVarInfoVarFound
  1530. dec bc
  1531. ld a,b
  1532. inc bc
  1533. sub 3
  1534. jr c,+_
  1535. ld bc,768
  1536. _:
  1537. pop af
  1538. ld de,saveSScreen
  1539. push bc
  1540. push de
  1541. call ReadArc
  1542. pop hl
  1543. pop bc
  1544. pop af
  1545. pop de
  1546. or a
  1547. jp z,BufCopy+3
  1548. ex de,hl
  1549. dec a
  1550. jp z,BufAND+3
  1551. dec a
  1552. jp z,BufXOR+3
  1553. dec a
  1554. jp z,BufOR+3
  1555. dec a
  1556. ret z
  1557. dec a
  1558. jp z,BufErase+3
  1559. ret
  1560. BBTokens:
  1561. ld a,(hl)
  1562. inc hl
  1563. cp $64 ;the G-T token
  1564. jr nz,lowercasetokens
  1565. ld a,(hl)
  1566. ld bc,plotSScreen
  1567. cp $AE
  1568. jr nz,+_
  1569. inc hl
  1570. ld bc,appBackUpScreen
  1571. _:
  1572. ld (parsePtr),hl
  1573. ret
  1574. lowercasetokens:
  1575. ld (parsePtr),hl
  1576. cp $31 ;the `e` token
  1577. jr nz,+_
  1578. call floatstackpush
  1579. push hl
  1580. ld de,float_e
  1581. ex de,hl
  1582. call mov4_page0
  1583. pop bc
  1584. ret
  1585. _:
  1586. cp $4B ;Pmt_End
  1587. jr nz,+_
  1588. ld bc,(stack_top)
  1589. ret
  1590. _:
  1591. cp $4C ;Pmt_Bgn
  1592. jr nz,+_
  1593. ld bc,(stack_base)
  1594. ret
  1595. _:
  1596. cp $B0
  1597. jr c,length
  1598. cp $CB
  1599. jr nc,length
  1600. cp $BB
  1601. jr c,+_
  1602. dec a
  1603. _:
  1604. sub $AC
  1605. add a,a
  1606. inc a
  1607. ex de,hl
  1608. ld l,a
  1609. ld h,91h
  1610. ld c,(hl)
  1611. inc l
  1612. ld b,(hl)
  1613. ex de,hl
  1614. ld a,(hl)
  1615. inc hl
  1616. call VarP
  1617. ret nc
  1618. ld (parsePtr),de
  1619. ld d,b
  1620. ld e,c
  1621. ld c,(hl)
  1622. inc hl
  1623. ld b,(hl)
  1624. set FactorialFlag,(iy+InternalFlag)
  1625. ret
  1626. length:
  1627. cp 2Bh \ jr nz,inString
  1628. ld a,(hl)
  1629. cp $AE ;'
  1630. jr nz,FindVarInfo
  1631. call ParseNextFullArg
  1632. push bc
  1633. call ParseNextFullArg
  1634. push bc
  1635. call ParseNextFullArg
  1636. push bc
  1637. ld bc,3Fh
  1638. cp 2Bh \ call z,ParseNextFullArg
  1639. ld a,c
  1640. pop de
  1641. pop bc
  1642. pop hl
  1643. call SearchLine_00
  1644. ld (ThetaPrimeVar),hl
  1645. ld b,d \ ld c,e
  1646. ret
  1647. ;HL is start address
  1648. ;BC is the line number
  1649. ;E is the NewLine byte
  1650. FindvarInfo:
  1651. call GetVarInfo2
  1652. ld (ThetaPrimeVar),hl
  1653. ret nc
  1654. ld bc,-1
  1655. ret
  1656. inString:
  1657. cp 15 \ jr nz,conj
  1658. call ParseFullArg
  1659. push bc
  1660. call ParseNextFullArg
  1661. pop hl
  1662. push bc ;second arg
  1663. push hl ;first arg
  1664. push af
  1665. ld h,b
  1666. ld l,c
  1667. call GetGrammerStr
  1668. pop af
  1669. pop hl
  1670. push bc ;size of second arg string
  1671. cp 2Bh ;If there is another argument, then it is to put a limit on how many bytes to compare
  1672. push hl
  1673. jr z,+_
  1674. call nz,GetGrammerStr
  1675. scf
  1676. _:
  1677. call nc,ParseNextFullArg
  1678. ld (ThetaPrimeVar),bc
  1679. pop hl
  1680. pop ix
  1681. pop de
  1682. call SearchString
  1683. jp nc,return_BC_0
  1684. ld b,h \ ld c,l
  1685. ret
  1686. conj:
  1687. ;n = f(x) = 440*(12th root (2^(x-48))
  1688. ;A=1, B=3, C=4, D=6, E=8, F=9, and G=11
  1689. ;Sharp is add 1
  1690. ;flat is minus 1
  1691. cp 37
  1692. jp nz,subToken
  1693. ld a,(hl)
  1694. cp $AE
  1695. jr nz,GrammerSound
  1696. call ParseNextFullArg
  1697. push bc
  1698. inc hl \ ld a,(hl)
  1699. cp $AE \ push af
  1700. call ParseNextFullArg
  1701. pop af
  1702. jr nz,SoundData
  1703. ld hl,freqout
  1704. ld (next_page_call_address),hl
  1705. ld h,b \ ld l,c \ pop bc
  1706. jp next_page_call
  1707. SoundData:
  1708. push bc
  1709. call ParseNextFullArg
  1710. ld hl,SoundLoop
  1711. ld (next_page_call_address),hl
  1712. pop hl \ pop de
  1713. ld a,b \ or c
  1714. jp nz,next_page_call
  1715. ret
  1716. GrammerSound:
  1717. call ParseFullArg
  1718. push bc
  1719. call ParseNextFullArg
  1720. ;Octave*12
  1721. ld h,b
  1722. ld l,c
  1723. add hl,hl
  1724. add hl,bc
  1725. add hl,hl
  1726. add hl,hl
  1727. ;Now add in the note
  1728. pop bc
  1729. add hl,bc
  1730. ;get offset into the LUT
  1731. add hl,hl
  1732. ;get the frequency
  1733. ld bc,FrequencyLUT
  1734. add hl,bc
  1735. ld c,(hl)
  1736. inc hl
  1737. ld b,(hl)
  1738. push bc
  1739. call ParseNextFullArg
  1740. ;multiply BC by 34483, then divide by 32
  1741. ld de,34483
  1742. call DE_Times_BC
  1743. xor a
  1744. add hl,hl \ rl e \ rl d \ rla
  1745. add hl,hl \ rl e \ rl d \ rla
  1746. add hl,hl \ rl e \ rl d \ rla
  1747. ld l,h \ ld h,e \ ld e,d \ ld d,a
  1748. ;DEHL is how long to run it
  1749. ld bc,noteloop_begin
  1750. ld (next_page_call_address),bc
  1751. pop bc
  1752. jp next_page_call
  1753. subToken:
  1754. cp 12 \ jr nz,ANOVAsubset
  1755. call ParseFullArg
  1756. push bc
  1757. call ParseNextFullArg
  1758. push bc
  1759. ld hl,(parsePtr)
  1760. inc hl
  1761. ld (parsePtr),hl
  1762. call GetVarInfo
  1763. jp c,Pop2Exit
  1764. or a \ jp nz,Pop2Exit
  1765. ld hl,(parsePtr)
  1766. ld (parsePtr),hl
  1767. ex de,hl
  1768. ld c,(hl) \ inc hl
  1769. ld b,(hl) \ inc hl
  1770. ld (TempWord1),hl
  1771. ld h,b \ ld l,c
  1772. pop bc
  1773. sbc hl,bc
  1774. pop de
  1775. ret c
  1776. sbc hl,de
  1777. jr nc,DelGoodSize
  1778. ex de,hl
  1779. add hl,de
  1780. ld h,a \ cp l \ ret z
  1781. ex de,hl
  1782. ld hl,0
  1783. DelGoodSize:
  1784. add hl,bc
  1785. push de
  1786. ld de,(TempWord1)
  1787. ex de,hl
  1788. dec hl \ ld (hl),d
  1789. dec hl \ ld (hl),e
  1790. inc hl \ inc hl
  1791. add hl,bc
  1792. pop de
  1793. push hl
  1794. ld a,d \ or e
  1795. jr z,+_
  1796. bcall(_DelMem)
  1797. _:
  1798. ld hl,(parsePtr)
  1799. ; ld (parsePtr),hl ;seems redundant, I probably messed up when I was cleaning the code.
  1800. pop bc
  1801. ret
  1802. ANOVAsubset:
  1803. DelvarToken:
  1804. cp 54h \ jr nz,UnArchiveToken
  1805. call GetVarInfo \ ret c
  1806. bcall(_DelVarArc)
  1807. ret
  1808. UnArchiveToken:
  1809. cp 69h \ jr nz,ArchiveToken
  1810. call GetVarInfo \ ret c
  1811. or a \ ret z
  1812. bcall(_Arc_Unarc)
  1813. call setup_readarc
  1814. bcall(_ChkFindSym)
  1815. ex de,hl
  1816. ld e,(hl) \ inc hl
  1817. ld d,(hl) \ inc hl
  1818. ex de,hl \ ld c,e \ ld b,d
  1819. ld (ThetaPrimeVar),hl
  1820. ret
  1821. ArchiveToken:
  1822. cp 68h \ jr nz,AsmToken
  1823. call GetVarInfo \ ret c
  1824. or a
  1825. ret nz
  1826. bcall(_Arc_Unarc)
  1827. setup_readarc:
  1828. call setupRAMdata
  1829. #ifndef include_TSA
  1830. ld hl,ReadArcData
  1831. ld de,TSA
  1832. ;mov 71 bytes
  1833. call mov14
  1834. call mov14
  1835. call mov14
  1836. call mov14
  1837. call mov15
  1838. in a,(6)
  1839. ld (page_restore),a
  1840. ld (bincomparepagerestore),a
  1841. #ifdef include_interrupt
  1842. dec a
  1843. ld (interrupt_page),a
  1844. #endif
  1845. #endif
  1846. ret
  1847. AsmToken:
  1848. cp 6Ah \ jr nz,expr
  1849. ; jr $
  1850. push bc
  1851. call GetVarName
  1852. ex de,hl
  1853. ld de,OP1
  1854. ldir
  1855. xor a
  1856. ld (de),a
  1857. ld hl,9D95h ;start VarRAM
  1858. ld (TempWord1),hl
  1859. pop hl \ ld (TempWord2),hl
  1860. bcall(_ChkFindSym)
  1861. ld a,b
  1862. ld (TempWord3),a
  1863. ex de,hl
  1864. ld c,(hl) \ inc hl
  1865. ld b,(hl) \ inc hl
  1866. ld a,(hl) \ inc hl \ cp $BB
  1867. ret nz
  1868. NotASMHeader:
  1869. ld a,(hl) \ inc hl \ cp $6D
  1870. jr nz,CheckUnsquishedHex
  1871. StartASMProg:
  1872. dec bc \ dec bc
  1873. ;BC is size of the data
  1874. ;HL points to the bytes to copy
  1875. ;(TempWord3) is the flash page
  1876. push hl \ push bc
  1877. ld h,b \ ld l,c
  1878. bcall(_EnoughMem)
  1879. jp c,ErrMEM
  1880. ex de,hl
  1881. ;HL # bytes
  1882. ;DE addr
  1883. ld de,9D95h ;start VarRAM
  1884. push de
  1885. bcall(_InsertMem)
  1886. pop de \ pop bc \ pop hl
  1887. ld a,(TempWord3) \ or a
  1888. jr nz,+_
  1889. add hl,bc
  1890. _:
  1891. push bc
  1892. call ReadArc
  1893. pop de
  1894. jr +_
  1895. CheckUnsquishedHex:
  1896. cp 6Ch \ jr nz,NotASMHeader
  1897. jr NotASMHeader
  1898. _:
  1899. ld hl,(parsePtr)
  1900. add hl,de
  1901. ld (parsePtr),hl
  1902. ;===============================================================
  1903. CallProg:
  1904. ld bc,(TempWord2)
  1905. push de
  1906. ld de,AfterRet \ push de
  1907. ld de,(TempWord1) \ push de
  1908. ret
  1909. AfterRET:
  1910. ld hl,(parsePtr)
  1911. pop de
  1912. or a
  1913. sbc hl,de
  1914. ld (parsePtr),hl
  1915. ld hl,9D95h ;start VarRAM
  1916. ;Delmem: HL address
  1917. ; DE # of bytes
  1918. bcall(_DelMem)
  1919. ret
  1920. expr:
  1921. cp 2Ah \ jr nz,AsmPrgm
  1922. call ParseFullArg
  1923. g_expr:
  1924. ld hl,(parsePtr) \ push hl
  1925. ld (parsePtr),bc
  1926. call ParseCondition
  1927. pop hl
  1928. ld (parsePtr),hl
  1929. ret
  1930. AsmPrgm:
  1931. cp 6Ch \ jr nz,OMNom
  1932. push bc
  1933. ld b,h \ ld c,l
  1934. call ConvHexTo86ECh
  1935. ex de,hl
  1936. ld (parsePtr),hl
  1937. pop bc
  1938. jp 86ECh
  1939. OMNom:
  1940. ;Note from Future Zeda: "I love you Past Zeda."
  1941. cp 5 \ jr nz,BBrandInt
  1942. #include "cmd/nom.z80"
  1943. BBrandInt:
  1944. cp 10 \ jr nz,BBLCM
  1945. call ParseFullArg
  1946. push bc
  1947. call ParseNextFullArg
  1948. push bc
  1949. call prng16
  1950. ld b,h
  1951. ld c,l
  1952. pop hl
  1953. pop de
  1954. or a \ sbc hl,de
  1955. push de
  1956. call HL_Times_BC
  1957. pop hl \ add hl,de
  1958. ld b,h \ ld c,l
  1959. ret
  1960. BBLCM:
  1961. cp 8
  1962. jr nz,BBGCD
  1963. call ParseFullArg
  1964. push bc
  1965. call ParseNextFullArg
  1966. pop de
  1967. LCM_BC_DE:
  1968. push de
  1969. call DE_Times_BC
  1970. ex (sp),hl
  1971. call GCDHL_BC
  1972. pop hl
  1973. call HL_Div_BC
  1974. ld b,h
  1975. ld c,l
  1976. ret
  1977. BBGCD:
  1978. cp 9
  1979. ret nz
  1980. call ParseFullArg
  1981. push bc
  1982. call ParseNextFullArg
  1983. pop hl
  1984. GCDHL_BC:
  1985. ld d,b
  1986. ld e,c
  1987. #include "math/gcdHL_DE.z80"
  1988. CircleToken:
  1989. #define circle_pattern TempWord1
  1990. call ParseFullArg ;Y
  1991. push bc
  1992. call ParseNextFullArg ;X
  1993. pop de
  1994. ld d,c
  1995. push de
  1996. call ParseNextFullArg ;R
  1997. push bc
  1998. cp 2Bh
  1999. ld c,1
  2000. call z,ParseNextFullArg ;Method
  2001. ld b,c
  2002. push bc
  2003. ld c,0
  2004. cp 2Bh
  2005. call z,ParseNextFullArg ;pattern
  2006. push bc
  2007. cp 2Bh
  2008. call z,ParseNextFullArg_Buffer ;buffer
  2009. pop hl
  2010. ld a,l
  2011. ld (circle_pattern),a
  2012. pop af ;method in A
  2013. pop de ;radius in E
  2014. pop bc
  2015. dec a
  2016. jr z,circle_bbcf
  2017. dec a
  2018. jr z,circle_wbcf
  2019. dec a
  2020. jr z,circle_xbcf
  2021. dec a
  2022. jr z,circle_wbwf
  2023. dec a
  2024. jr z,circle_bbbf
  2025. dec a
  2026. jr z,circle_xbxf
  2027. dec a
  2028. jr z,circle_wbbf
  2029. dec a
  2030. jr z,circle_wbxf
  2031. dec a
  2032. jr z,circle_bbwf
  2033. dec a
  2034. jr z,circle_bbxf
  2035. dec a
  2036. jr z,circle_xbwf
  2037. dec a
  2038. ret nz
  2039. circle_xbbf:
  2040. push de
  2041. push bc
  2042. call circle_xbcf
  2043. pop bc
  2044. pop de
  2045. jr circle_bf
  2046. circle_wbcf:
  2047. ld ix,pixelOff_pattern
  2048. jr circle_p0
  2049. circle_bbcf:
  2050. ld ix,pixelOn_pattern
  2051. jr circle_p0
  2052. circle_xbcf:
  2053. ld ix,pixelToggle_pattern
  2054. jr circle_p0
  2055. circle_wbwf:
  2056. push de
  2057. push bc
  2058. call circle_wbcf
  2059. pop bc
  2060. pop de
  2061. circle_wf:
  2062. ld ix,horizline_white
  2063. jp drawfilledcircle
  2064. circle_bbbf:
  2065. push de
  2066. push bc
  2067. call circle_bbcf
  2068. pop bc
  2069. pop de
  2070. circle_bf:
  2071. ld ix,horizline_black
  2072. jp drawfilledcircle
  2073. circle_xbxf:
  2074. push de
  2075. push bc
  2076. call circle_xbcf
  2077. pop bc
  2078. pop de
  2079. circle_xf:
  2080. ld ix,horizline_invert
  2081. jp drawfilledcircle
  2082. circle_wbbf:
  2083. push de
  2084. push bc
  2085. call circle_wbcf
  2086. pop bc
  2087. pop de
  2088. jr circle_bf
  2089. circle_wbxf:
  2090. push de
  2091. push bc
  2092. call circle_wbcf
  2093. pop bc
  2094. pop de
  2095. jr circle_xf
  2096. circle_bbwf:
  2097. push de
  2098. push bc
  2099. call circle_bbcf
  2100. pop bc
  2101. pop de
  2102. jr circle_wf
  2103. circle_bbxf:
  2104. push de
  2105. push bc
  2106. call circle_bbcf
  2107. pop bc
  2108. pop de
  2109. jr circle_xf
  2110. circle_xbwf:
  2111. push de
  2112. push bc
  2113. call circle_xbcf
  2114. pop bc
  2115. pop de
  2116. jr circle_wf
  2117. circle_p0:
  2118. push hl
  2119. ld hl,circle
  2120. ld (next_page_call_address),hl
  2121. pop hl
  2122. jp next_page_call
  2123. drawfilledcircle:
  2124. push hl
  2125. ld hl,filledcircle
  2126. ld (next_page_call_address),hl
  2127. pop hl
  2128. jp next_page_call
  2129. PauseToken:
  2130. ld a,(hl)
  2131. call EndOArg
  2132. call nz,isop
  2133. push bc
  2134. jr nz,NotBASICPause
  2135. _:
  2136. bit OnBlockFlag,(iy+UserFlags)
  2137. call z,onbreak
  2138. call GetKeyDebounce
  2139. cp 9
  2140. jr nz,-_
  2141. _:
  2142. bit OnBlockFlag,(iy+UserFlags)
  2143. call z,onbreak
  2144. call GetKeyDebounce
  2145. or a
  2146. jr nz,-_
  2147. pop bc
  2148. ret
  2149. NotBASICPause:
  2150. ld a,(hl) \ cp $CE \ jr nz,Pause
  2151. bit invlogic,(iy+gflags)
  2152. res invlogic,(iy+gflags)
  2153. inc hl
  2154. jr z,Pauseif
  2155. jr PauseNotIf
  2156. Pause:
  2157. call ParseFullArg
  2158. pop de
  2159. g_Pause:
  2160. push de
  2161. ei
  2162. _:
  2163. bit OnBlockFlag,(iy+UserFlags)
  2164. call z,onbreak
  2165. halt
  2166. dec bc
  2167. ld a,b
  2168. or c
  2169. jr nz,-_
  2170. pop bc
  2171. ret
  2172. PauseIf:
  2173. call PauseIfLoop
  2174. jr nz,PauseIf
  2175. pop bc \ ret
  2176. PauseNotIf:
  2177. call PauseIfLoop
  2178. jr z,PauseNotIf
  2179. pop bc \ ret
  2180. PauseIfLoop:
  2181. ld (parsePtr),hl
  2182. push hl
  2183. call ParseCondition
  2184. ld a,b
  2185. or c
  2186. pop hl
  2187. ret
  2188. PxlTokens:
  2189. sub $A0
  2190. PxlTestToken:
  2191. push af
  2192. ld a,(hl)
  2193. cp $AE
  2194. ;jr z,PxlTestBox
  2195. jp z,ErrBadToken
  2196. call ParseFullArg
  2197. push bc
  2198. call ParseNextFullArg
  2199. cp 2Bh
  2200. ld a,c
  2201. push af
  2202. call z,ParseNextFullArg_Buffer
  2203. pop af
  2204. pop bc
  2205. ld b,a
  2206. pop de
  2207. PlotPixel:
  2208. call GetPixelLoc
  2209. ld bc,0
  2210. jr c,+_
  2211. bit pxlBoundsRes,(iy+UserFlags)
  2212. ret z
  2213. inc c
  2214. ret
  2215. _:
  2216. ld e,a
  2217. and (hl)
  2218. jr z,+_
  2219. inc c
  2220. _:
  2221. dec d
  2222. jr nz,+_
  2223. ld a,e \ or (hl) \ ld (hl),a \ ret
  2224. _:
  2225. dec d
  2226. jr z,+_
  2227. dec d
  2228. ret nz
  2229. ld a,e
  2230. _:
  2231. xor (hl) \ ld (hl),a \ ret
  2232. prgmToken:
  2233. ld (TempWord1),bc
  2234. ld a,(hl) \ inc hl
  2235. cp $10
  2236. jr nz,+_
  2237. ld (parsePtr),hl
  2238. ld a,(hl)
  2239. inc hl
  2240. _:
  2241. push af
  2242. call VarP
  2243. ex (sp),hl
  2244. push af
  2245. push hl
  2246. call ParseFullArg
  2247. pop af
  2248. jr nz,g_Call
  2249. inc hl
  2250. ld (qmarkVar),hl
  2251. .db $C2 ;start of jp nz,*, basically skips the 'or 1'
  2252. g_Call:
  2253. or 1
  2254. push af
  2255. ld de,(progStart)
  2256. ld hl,(parsePtr)
  2257. or a
  2258. sbc hl,de
  2259. push hl
  2260. ex de,hl
  2261. sbc hl,bc
  2262. push hl
  2263. ld (parsePtr),bc
  2264. ld bc,(TempWord1)
  2265. call ParserNext
  2266. pop hl
  2267. pop de
  2268. push hl
  2269. ld hl,(progStart)
  2270. add hl,de
  2271. ld (parsePtr),hl
  2272. pop de
  2273. ld hl,(progStart)
  2274. sbc hl,de
  2275. ex de,hl
  2276. pop af
  2277. jr nz,+_
  2278. pop af
  2279. pop hl
  2280. ld hl,(qmarkVar)
  2281. ld (parsePtr),hl
  2282. ret
  2283. _:
  2284. pop af \ pop hl
  2285. ret nc
  2286. ld (hl),e \ inc hl
  2287. ld (hl),d
  2288. ret
  2289. DispToken:
  2290. ld a,(hl)
  2291. cp 11
  2292. jr z,GrayBufOnly
  2293. cp $AE
  2294. jr z,BlackBufOnly
  2295. call ParseFullArg
  2296. ld (BufPtr),bc
  2297. ld (GrayBufPtr),bc
  2298. ret
  2299. GrayBufOnly:
  2300. call ParseNextFullArg
  2301. ld (GrayBufPtr),bc
  2302. ret
  2303. BlackBufOnly:
  2304. call ParseNextFullArg
  2305. ld (BufPtr),bc
  2306. ret
  2307. TextToken:
  2308. ld a,(hl)
  2309. cp 4 \ jr z,+_
  2310. cp 3Eh \ jr z,+_
  2311. cp 3Fh \ jr nz,NoRC
  2312. _:
  2313. ld bc,(textRow)
  2314. ld l,b \ ld b,0
  2315. ld h,b
  2316. ld (ThetaPrimeVar),hl
  2317. ret
  2318. NoRC:
  2319. res SlowTextFlag,(iy+InternalFlag)
  2320. cp 10
  2321. jr nz,+_
  2322. SlowText:
  2323. set SlowTextFlag,(iy+InternalFlag)
  2324. inc hl
  2325. ld (parsePtr),hl
  2326. ld a,(hl)
  2327. _:
  2328. cp $AE
  2329. jp nz,FindingTextStr
  2330. inc hl
  2331. ld (parsePtr),hl
  2332. call LoadTextCoordinates
  2333. call ParseNextFullArg
  2334. push bc
  2335. push de
  2336. ld a,(hl)
  2337. cp 2Bh
  2338. ld c,10
  2339. call z,ParseNextFullArg+3
  2340. pop hl
  2341. pop de
  2342. bit SignedText,(iy+UserFlags)
  2343. jr z,+_
  2344. bit 7,d
  2345. jr z,+_
  2346. xor a \ sub e \ ld e,a
  2347. sbc a,a \ sub d \ ld d,a
  2348. ; ld a,b \ sbc a,e \ ld e,a
  2349. ; ld a,b \ sbc a,d \ ld d,a
  2350. push de \ push hl \ push bc
  2351. ld a,1Ah \ call PutSC
  2352. pop bc \ pop hl \ pop de
  2353. _:
  2354. dec c
  2355. ret z
  2356. inc c
  2357. ret z
  2358. push de
  2359. pop ix
  2360. ld de,OP2
  2361. xor a
  2362. ld (de),a
  2363. DispNumBase32:
  2364. ;Inputs:
  2365. ; C is the base (use 2 to 36)
  2366. ; HLIX is the number to display
  2367. ; IX points to where to write the string
  2368. call HLIX_Div_C
  2369. add a,30h
  2370. cp 3Ah
  2371. jr c,+_
  2372. add a,7
  2373. _:
  2374. dec de
  2375. ld (de),a
  2376. ld a,ixh
  2377. or ixl \ or h \ or l
  2378. jr nz,DispNumBase32
  2379. ex de,hl
  2380. jp GPutS
  2381. FindingTextStr:
  2382. call LoadTextCoordinates
  2383. ret nz
  2384. inc hl
  2385. ld a,(hl)
  2386. cp 3Ah ;. displays a float
  2387. jr nz,+_
  2388. ld (parsePtr),hl
  2389. call ParseNextFullArg
  2390. ld hl,single2str
  2391. ld (next_page_call_address),hl
  2392. ld h,b
  2393. ld l,c
  2394. ld bc,OP1
  2395. call next_page_call
  2396. ld h,b
  2397. ld l,c
  2398. jp GPutS
  2399. _:
  2400. cp $AE
  2401. jr nz,+_
  2402. ld (parsePtr),hl
  2403. call ParseNextFullArg
  2404. ld a,c
  2405. jp PutSC
  2406. _:
  2407. cp 11
  2408. jr nz,+_
  2409. ld (parsePtr),hl
  2410. call ParseNextFullArg
  2411. ld h,b \ ld l,c
  2412. jp GPutS
  2413. _:
  2414. call ParseNextFullArg
  2415. push bc
  2416. cp 2Bh
  2417. jr nz,+_
  2418. call ParseNextFullArg
  2419. set Xis0,(iy+ParticleFlag)
  2420. xor a
  2421. _:
  2422. pop hl
  2423. jr z,TokenTextLoop
  2424. PutTokenText:
  2425. ; HL points to the string
  2426. res Xis0,(iy+ParticleFlag)
  2427. ld bc,-1
  2428. TokenTextLoop:
  2429. ld a,(hl)
  2430. bit Xis0,(iy+ParticleFlag)
  2431. jr nz,+_
  2432. or a
  2433. ret z
  2434. cp 4
  2435. ret z
  2436. cp 3Fh
  2437. ret z
  2438. cp 2Ah
  2439. ret z
  2440. _:
  2441. push hl
  2442. push bc
  2443. bcall(_Get_Tok_Strng)
  2444. pop hl
  2445. or a
  2446. sbc hl,bc
  2447. jr nc,+_
  2448. add hl,bc
  2449. ld b,h
  2450. ld c,l
  2451. ld l,0
  2452. _:
  2453. ex (sp),hl
  2454. ld a,(hl)
  2455. call Is_2_Byte
  2456. jr nz,+_
  2457. inc hl
  2458. _:
  2459. push hl
  2460. ld hl,OP3
  2461. call PutSM
  2462. pop hl
  2463. pop bc
  2464. inc bc
  2465. cpi
  2466. jp pe,TokenTextLoop
  2467. ret
  2468. ;===============================================================
  2469. LoadTextCoordinates:
  2470. ;===============================================================
  2471. ld a,(hl)
  2472. cp 11
  2473. jr nz,+_
  2474. ld (parsePtr),hl
  2475. ret
  2476. _:
  2477. ld bc,(textRow)
  2478. call ParseFullArg
  2479. ld a,c
  2480. ld (textRow),a
  2481. ld bc,(textCol)
  2482. call ParseNextFullArg
  2483. ld a,c
  2484. ld (textCol),a
  2485. ld a,(hl)
  2486. cp 2Bh
  2487. ret
  2488. ;===============================================================
  2489. PtOff:
  2490. call ParseFullArg
  2491. ld a,c
  2492. and 7
  2493. push af
  2494. bit 3,c
  2495. push af
  2496. call ParseNextFullArg
  2497. pop af
  2498. jr z,+_
  2499. call ConvHexTo86ECh
  2500. ld bc,86ECh
  2501. _:
  2502. push bc
  2503. call ParseNextFullArg
  2504. push bc
  2505. call ParseNextFullArg
  2506. pop de
  2507. ld d,c
  2508. push de
  2509. cp 2Bh
  2510. ld c,1
  2511. call z,ParseNextFullArg
  2512. push bc
  2513. cp 2Bh
  2514. ld c,8
  2515. call z,ParseNextFullArg
  2516. pop hl
  2517. ld h,c
  2518. push hl
  2519. ld hl,(parsePtr)
  2520. ld a,(hl)
  2521. cp $2B
  2522. call z,ParseNextFullArg_Buffer
  2523. pop hl
  2524. pop bc
  2525. pop de
  2526. pop af
  2527. jr sprite
  2528. #include "gfx/bigsprite.z80"
  2529. LineToken:
  2530. ld a,(hl)
  2531. cp $AE
  2532. jp z,gfx_line
  2533. ; A is the type of rectangle to draw
  2534. ; 0 =White
  2535. ; 1 =Black
  2536. ; 2 =XOR
  2537. ; 3 =Black border
  2538. ; 4 =White border
  2539. ; 5 =XOR border
  2540. ; 6 =Black border, white inside
  2541. ; 7 =Black border, XOR inside
  2542. ; 8 =White border, black inside
  2543. ; 9 =White border, XOR inside
  2544. ; 10=Shift Up
  2545. ; 11=Shift Down
  2546. ; B is the height
  2547. ; C is the Y pixel coordinate
  2548. ; D is the width in pixels
  2549. ; E is is the X pixel coordinate
  2550. ;So we get E,C,B,D,A
  2551. call ParseFullArg
  2552. push bc
  2553. call ParseNextFullArg
  2554. push bc
  2555. call ParseNextFullArg
  2556. pop hl
  2557. ld h,c
  2558. push hl
  2559. call ParseNextFullArg
  2560. push bc
  2561. cp 2Bh
  2562. ld c,1
  2563. call z,ParseNextFullArg
  2564. push bc
  2565. cp 2Bh
  2566. call z,ParseNextFullArg_Buffer
  2567. pop bc ;method in C
  2568. ld a,c
  2569. pop hl ;L is what needs to be the D value
  2570. pop bc
  2571. pop de
  2572. ld d,l
  2573. jp DrawRectToGraph
  2574. gfx_line:
  2575. ;x1,y1,x2,y2[,method[,buffer
  2576. ;
  2577. call ParseNextFullArg
  2578. push bc
  2579. call ParseNextFullArg
  2580. pop de
  2581. ld b,e
  2582. push bc
  2583. call ParseNextFullArg
  2584. push bc
  2585. call ParseNextFullArg
  2586. pop de
  2587. ld b,e
  2588. push bc
  2589. ld c,1
  2590. cp $2B
  2591. call z,ParseNextFullArg
  2592. ;Now get the pointer to the plotting function
  2593. ld b,a ;save A
  2594. ld a,c
  2595. cp 3
  2596. sbc a,a
  2597. and c
  2598. add a,a
  2599. add a,plotLUT&255
  2600. ld l,a
  2601. ld a,plotLUT>>8
  2602. adc a,0
  2603. ld h,a
  2604. ld c,(hl)
  2605. inc hl
  2606. ld a,b ;restore A
  2607. ld b,(hl)
  2608. push bc
  2609. cp $2B
  2610. call z,ParseNextFullArg_Buffer
  2611. pop ix
  2612. pop de
  2613. pop hl
  2614. #include "gfx/line.z80"
  2615. plotLUT:
  2616. .dw pxloff
  2617. .dw pxlon
  2618. .dw pxlchange
  2619. LeftParantheses:
  2620. ;Read a byte
  2621. call ParseFullArg
  2622. ld h,b
  2623. ld l,c
  2624. ld c,(hl)
  2625. ld b,0
  2626. ret
  2627. LeftBracket:
  2628. ;Read a word (little endian)
  2629. call ParseFullArg
  2630. ld h,b
  2631. ld l,c
  2632. ld c,(hl)
  2633. inc hl
  2634. ld b,(hl)
  2635. ret
  2636. iPart:
  2637. ;Write a word (little endian)
  2638. call ParseFullArg
  2639. push bc
  2640. call ParseNextFullArg
  2641. pop hl
  2642. ld e,(hl)
  2643. ld (hl),c
  2644. inc hl
  2645. ld d,(hl)
  2646. ld (hl),b
  2647. ld b,d
  2648. ld c,e
  2649. ret
  2650. int:
  2651. ;Write byte
  2652. ld a,(hl)
  2653. cp $3A
  2654. jr z,intf
  2655. cp $AE ;checks for '
  2656. push af
  2657. call ParseFullArg
  2658. push bc
  2659. call ParseNextFullArg
  2660. pop hl
  2661. pop af
  2662. jr nz,+_ ;Write a byte
  2663. ld a,(bc)
  2664. ld e,(hl)
  2665. ld (hl),a
  2666. ld a,e
  2667. ld (bc),a
  2668. ret
  2669. _:
  2670. ld e,(hl)
  2671. ld (hl),c
  2672. ld c,e
  2673. ld b,$00
  2674. ret
  2675. intf:
  2676. call ParseNextFullArg
  2677. ld hl,singleTo_int16
  2678. ld (next_page_call_address),hl
  2679. ld h,b
  2680. ld l,c
  2681. call next_page_call
  2682. ld b,h
  2683. ld c,l
  2684. ret
  2685. GetToken:
  2686. ld a,(hl)
  2687. cp $AE
  2688. jp z,GetByte
  2689. call GetVarName
  2690. ex de,hl
  2691. ld de,OP1
  2692. ldir
  2693. xor a
  2694. ld (de),a
  2695. bcall(_ChkFindSym)
  2696. VarTokenStepIn:
  2697. jp c,return_BC_0
  2698. ex de,hl
  2699. ld a,b
  2700. or a
  2701. jr z,+_
  2702. ld b,0
  2703. add hl,bc
  2704. ld c,10
  2705. adc hl,bc
  2706. jp p,+_
  2707. ld h,$40
  2708. inc a
  2709. _:
  2710. ld (ThetaPrimeVar),a
  2711. inc hl
  2712. inc hl
  2713. ld b,h
  2714. ld c,l
  2715. ret
  2716. RepeatToken:
  2717. push hl
  2718. ex de,hl
  2719. pop hl
  2720. call EndOfLine
  2721. ld (parsePtr),hl
  2722. bit invlogic,(iy+gflags)
  2723. res invlogic,(iy+gflags)
  2724. jr nz,NotRepeatLoop
  2725. RepeatLoop:
  2726. call RepeatLooper
  2727. jr z,RepeatLoop
  2728. ExitRepeat:
  2729. ld (parsePtr),hl
  2730. ret
  2731. NotRepeatLoop:
  2732. call RepeatLooper
  2733. jr nz,NotRepeatLoop
  2734. jr ExitRepeat
  2735. RepeatLooper:
  2736. push de
  2737. call ParserNext
  2738. ld hl,(parsePtr)
  2739. pop de
  2740. push de
  2741. push hl
  2742. ld (parsePtr),de
  2743. push bc
  2744. call ParseCondition
  2745. ld a,b \ or c
  2746. Pop3Exit:
  2747. pop bc
  2748. Pop2Exit:
  2749. pop hl
  2750. Pop1Exit:
  2751. pop de
  2752. ret
  2753. WhileToken:
  2754. bit invlogic,(iy+gflags)
  2755. res invlogic,(iy+gflags)
  2756. jr nz,NotWhileLoop
  2757. WhileLoop:
  2758. push hl
  2759. ld (parsePtr),hl
  2760. call ParseCondition
  2761. ld a,b
  2762. or c
  2763. jr z,EndWhileLoop
  2764. call ParserNext
  2765. pop hl
  2766. jr WhileLoop
  2767. NotWhileLoop:
  2768. push hl
  2769. ld (parsePtr),hl
  2770. call ParseCondition
  2771. ld a,b
  2772. or c
  2773. jr nz,EndWhileLoop
  2774. call ParserNext
  2775. pop hl
  2776. jr NotWhileLoop
  2777. EndWhileLoop:
  2778. pop de
  2779. call FindEndToken
  2780. ld (parsePtr),hl
  2781. ret
  2782. EndToken:
  2783. pop de
  2784. ret
  2785. ErrorJump:
  2786. ; If we are currently parsing an errorthen we don't want to be stuck in an infinite loop !
  2787. bit errorChecking,(iy+InternalFlag)
  2788. ret nz
  2789. set errorChecking,(iy+InternalFlag)
  2790. push de
  2791. push hl
  2792. push bc
  2793. ld hl,(parsePtr)
  2794. ld (ErrorLoc),hl
  2795. ld hl,(parseError)
  2796. ld a,h
  2797. or l
  2798. ld a,(cxErrorEP)
  2799. call z,GramHandl
  2800. jr z,L5c05
  2801. ld c,a
  2802. ld b,0
  2803. ld de,(parsePtr)
  2804. ld (qmarkVar),de
  2805. ld (parsePtr),hl
  2806. ld hl,(ThetaPrimeVar)
  2807. push hl
  2808. ld hl,(Ans)
  2809. ld (Ans),bc
  2810. push hl
  2811. call ParserNext
  2812. ld a,(hl)
  2813. ld hl,(qmarkVar)
  2814. ld (parsePtr),hl
  2815. cp $11
  2816. jr nz,+_
  2817. pop hl
  2818. pop hl
  2819. pop hl
  2820. jr L5c06
  2821. _:
  2822. pop hl
  2823. ld (Ans),hl
  2824. pop hl
  2825. ld (ThetaPrimeVar),hl
  2826. L5c05:
  2827. pop bc
  2828. L5c06:
  2829. pop hl
  2830. pop de
  2831. res errorChecking,(iy+InternalFlag)
  2832. ret
  2833. PtOn:
  2834. call ParseFullArg
  2835. ld a,c \ and 7
  2836. res SlowTextFlag,(iy+InternalFlag)
  2837. bit 3,c
  2838. jr z,+_
  2839. set SlowTextFlag,(iy+InternalFlag)
  2840. _:
  2841. push af
  2842. cp 7 \ jr nz,+_
  2843. ld hl,flags+33
  2844. ld a,16
  2845. xor (hl)
  2846. ld (hl),a
  2847. _:
  2848. call ParseNextFullArg
  2849. bit SlowTextFlag,(iy+InternalFlag)
  2850. jr z,+_
  2851. call ConvHexTo86ECh
  2852. ld bc,saveSScreen
  2853. _:
  2854. push bc
  2855. call ParseNextFullArg
  2856. ld (TempWord2),bc
  2857. ld b,0
  2858. ld h,b
  2859. ld l,c
  2860. add hl,hl
  2861. add hl,bc
  2862. add hl,hl
  2863. add hl,hl
  2864. push hl
  2865. call ParseNextFullArg
  2866. pop hl
  2867. add hl,bc
  2868. push hl
  2869. cp 2Bh
  2870. ld c,1
  2871. call z,ParseNextFullArg
  2872. ld b,c
  2873. push bc
  2874. cp 2Bh
  2875. ld c,$08
  2876. call z,ParseNextFullArg
  2877. pop af
  2878. ld b,a
  2879. ld a,(TempWord2)
  2880. add a,c \ dec a \ sub 64
  2881. jr c,HeightIsFinePtOn
  2882. ld d,a \ ld a,c \ sub d \ ld c,a \ dec c
  2883. HeightIsFinePtOn:
  2884. push bc
  2885. ld bc,(BufPtr)
  2886. ld hl,(parsePtr)
  2887. ld a,(hl)
  2888. cp 2Bh
  2889. call z,ParseNextFullArg
  2890. ld d,b \ ld e,c
  2891. pop bc
  2892. pop hl
  2893. add hl,de
  2894. pop de
  2895. ld a,(TempWord2) \ inc a \ sub 64 \ jp nc,pop1exit
  2896. pop af
  2897. DrawSpriteXxY:
  2898. push hl
  2899. ld hl,bigtile
  2900. ld (next_page_call_address),hl
  2901. pop hl
  2902. jp next_page_call
  2903. QuoteToken:
  2904. push hl
  2905. call GetGrammerStr
  2906. ld (parsePtr),hl
  2907. ld (ThetaPrimeVar),bc
  2908. pop bc
  2909. ret
  2910. GetKeyToken:
  2911. ld a,(hl)
  2912. cp 16
  2913. jr nz,GetKey
  2914. call ParseNextFullArg+3
  2915. ld a,c
  2916. CheckKey:
  2917. ;46 bytes:
  2918. ;Input:
  2919. ; A is the key to test for
  2920. ;Output:
  2921. ; BC is 1 if the key is pressed, 0 if it is not
  2922. ; z if the key is pressed, nz if not
  2923. cp 41 ;on-key
  2924. jr z,check_for_ON_key
  2925. di
  2926. _:
  2927. dec a \ and 63
  2928. ld b,a
  2929. and 7
  2930. srl b \ srl b \ srl b
  2931. inc b \ inc a
  2932. ;b = 2; a = 1
  2933. ld c,a
  2934. ld a,7Fh
  2935. _:
  2936. rlca
  2937. djnz -_
  2938. out (1),a
  2939. ld b,c
  2940. ld a,80h
  2941. _:
  2942. rlca
  2943. djnz -_
  2944. ld c,a
  2945. in a,(1)
  2946. and c
  2947. CheckKey_End:
  2948. ld c,b
  2949. ret nz
  2950. inc c
  2951. ret
  2952. check_for_ON_key:
  2953. in a,(4)
  2954. and 8
  2955. ld bc,0
  2956. ret nz
  2957. inc c
  2958. ret
  2959. GetKeyDebounce:
  2960. ei
  2961. halt
  2962. call GetKey
  2963. ld hl,k_save
  2964. cp (hl)
  2965. jr nz,newkeypress
  2966. ;if the keys match, decrement k_count
  2967. inc hl
  2968. dec (hl)
  2969. jr z,+_
  2970. xor a
  2971. ret
  2972. _:
  2973. inc hl
  2974. ld a,(hl)
  2975. sub K_DELAY_ACCEL+1
  2976. jr nc,+_
  2977. xor a
  2978. _:
  2979. inc a
  2980. ld (hl),a
  2981. dec hl
  2982. ld (hl),a
  2983. dec hl
  2984. ld a,(hl)
  2985. ret
  2986. newkeypress:
  2987. ld (hl),a
  2988. inc hl
  2989. ld (hl),K_DELAY_DEFAULT
  2990. inc hl
  2991. ld (hl),K_DELAY_DEFAULT
  2992. ret
  2993. ;===============================================================
  2994. GetKey:
  2995. ;===============================================================
  2996. ;Outputs:
  2997. ; a is a value from 0 to 56 that is the keypress
  2998. ; bc is also the key press
  2999. ; d has a bit reset, the rest are set (this is the last key group tested)
  3000. ; e is a with a mask of %11111000
  3001. ; hl is not modified
  3002. ;===============================================================
  3003. di
  3004. ld de,$FE00
  3005. ld a,d
  3006. out (1),a
  3007. push af \ pop af
  3008. in a,(1)
  3009. ld b,e
  3010. xor $FF \ jr z,+_
  3011. ld d,a
  3012. ld c,16 \ cp 15 \ ret z
  3013. ld c,5
  3014. ld a,3 \ and d \ cp 3 \ ret z \ inc c
  3015. ld a,5 \ and d \ cp 5 \ ret z \ inc c
  3016. ld a,10 \ and d \ cp 10 \ ret z \ inc c
  3017. ld a,12 \ and d \ cp 12 \ ret z
  3018. ld a,d
  3019. cpl
  3020. ld c,e
  3021. jp key_add
  3022. _:
  3023. ld c,a
  3024. _:
  3025. rlc d
  3026. ld a,d
  3027. out (1),a
  3028. inc e
  3029. sub 7Fh
  3030. jp z,CheckOnPress
  3031. in a,(1)
  3032. inc a
  3033. jr z,-_
  3034. dec a
  3035. key_add:
  3036. inc c
  3037. rra
  3038. jr c,key_add
  3039. ld a,e
  3040. rlca \ rlca \ rlca
  3041. add a,c
  3042. ld c,a
  3043. ret
  3044. CheckOnPress:
  3045. in a,(4)
  3046. and 8
  3047. sub 1
  3048. sbc a,a
  3049. and 41
  3050. ld c,a
  3051. ret
  3052. ElseToken:
  3053. ;Check for an If token, maybe?
  3054. push bc
  3055. call FindEndToken
  3056. ld (parsePtr),hl
  3057. pop bc
  3058. pop af
  3059. ret
  3060. IfToken:
  3061. push bc
  3062. call ParseCondition
  3063. ld a,b
  3064. or c
  3065. jr z,+_
  3066. scf
  3067. _:
  3068. pop bc
  3069. ld hl,flags+gflags
  3070. bit invlogic,(hl)
  3071. jr z,+_
  3072. res invlogic,(hl)
  3073. ccf
  3074. _:
  3075. ret c
  3076. ld hl,(parsePtr)
  3077. inc hl
  3078. ld a,(hl)
  3079. push bc
  3080. cp $CF ;Then token
  3081. jr z,nothen
  3082. call EndOfLine
  3083. _:
  3084. ld (parsePtr),hl
  3085. pop bc
  3086. ret
  3087. nothen:
  3088. call z,FindElseEnd
  3089. cp $D0 ;Check if it was an Else token
  3090. jr nz,-_
  3091. ld (parsePtr),hl
  3092. pop bc
  3093. jp ParserNext
  3094. VarToken:
  3095. call VarP
  3096. ld (parsePtr),de
  3097. ld c,(hl)
  3098. inc hl
  3099. ld b,(hl)
  3100. ex de,hl
  3101. ld a,(hl)
  3102. inc hl
  3103. call VarP
  3104. ret nc
  3105. ld (parsePtr),de
  3106. ld e,c
  3107. ld d,b
  3108. ld c,(hl)
  3109. inc hl
  3110. ld b,(hl)
  3111. set FactorialFlag,(iy+InternalFlag)
  3112. ret
  3113. ParseNextFullArg_Buffer:
  3114. ;Input: z flag
  3115. ;Result:
  3116. ; z : Parse the next argument, result in BC
  3117. ; nz : Returns BC as the pointer to the main buffer
  3118. ld bc,(BufPtr)
  3119. call z,ParseNextFullArg
  3120. ld (gbuf_temp),bc
  3121. ret
  3122. ParseNextFullArg:
  3123. ld hl,(parsePtr)
  3124. ParseNextFullArg_Inc:
  3125. inc hl
  3126. ParseNextFullArg_HL:
  3127. ld (parsePtr),hl
  3128. ParseFullArg:
  3129. bit FactorialFlag,(iy+InternalFlag)
  3130. jr nz,+_
  3131. ld de,0
  3132. _:
  3133. res FactorialFlag,(iy+InternalFlag)
  3134. ld hl,(parsePtr)
  3135. ld a,(hl)
  3136. call EndOArg
  3137. ret z
  3138. cp 29h
  3139. ret z
  3140. call ParseArg
  3141. jr ParseFullArg
  3142. ParseCondition:
  3143. call ParseArg
  3144. ld hl,(parsePtr)
  3145. ld a,3Fh
  3146. cp (hl)
  3147. jr nz,ParseCondition
  3148. ret
  3149. GetNextVarNum:
  3150. inc hl
  3151. ld a,(hl)
  3152. cp $AE
  3153. jr nz,+_
  3154. set Mod2nd,(iy+InternalFlag)
  3155. ret
  3156. _:
  3157. sub 3Ah
  3158. add a,10
  3159. ret nc
  3160. ld a,d
  3161. add a,a
  3162. add a,a
  3163. add a,d
  3164. add a,a
  3165. ld d,a
  3166. ld a,(hl)
  3167. and 15
  3168. add a,d
  3169. ld d,a
  3170. jr GetNextVarNum
  3171. StoString:
  3172. ld e,a
  3173. ld d,(hl)
  3174. inc d
  3175. call GetNextVarNum
  3176. dec d
  3177. ld (parsePtr),hl
  3178. ld h,b
  3179. ld l,c
  3180. push bc ;Data in Grammer prg
  3181. push de ;D= Str Nr; E=AA
  3182. call GetGrammerStr
  3183. pop hl
  3184. bit Mod2nd,(iy+InternalFlag)
  3185. jr z,+_
  3186. inc bc
  3187. _:
  3188. push bc
  3189. ld b,h
  3190. ld c,l
  3191. ld (OP1+1),hl
  3192. xor a
  3193. ld (OP1+3),a
  3194. ld (OP1+1),bc
  3195. rst rFindSym
  3196. jr c,+_
  3197. ;HL = pointer to the variable's Symbol Table entry
  3198. ;DE = pointer to the variable's data structure
  3199. ;B = 0 for Ram, or Flashpage
  3200. ;OP1=.db StrngObj,tVarStrng,tStr1,0,0; not all n�tig
  3201. bcall(_DelVarArc)
  3202. _:
  3203. pop hl ;length
  3204. push hl
  3205. bcall(_CreateStrng)
  3206. inc de
  3207. inc de
  3208. pop bc
  3209. pop hl
  3210. ldir
  3211. bit Mod2nd,(iy+InternalFlag)
  3212. ret z
  3213. res Mod2nd,(iy+InternalFlag)
  3214. dec de
  3215. ld a,3Fh
  3216. ld (de),a
  3217. ret
  3218. StoDisp:
  3219. ld (parsePtr),hl
  3220. ld h,c
  3221. ld l,c
  3222. ld a,c
  3223. cp 16
  3224. jr nc,+_
  3225. inc c
  3226. dec c
  3227. jr z,+_
  3228. ld l,%10101010
  3229. dec c
  3230. jr z,+_
  3231. setgray4:
  3232. ld hl,%0000001011011011 ;H is 2
  3233. _:
  3234. ld (graymask),hl
  3235. ret
  3236. StoToken:
  3237. ld a,(hl)
  3238. inc hl
  3239. cp $AA \ jp z,StoString
  3240. cp $DC \ jp z,StoInput
  3241. cp $DE \ jr z,StoDisp
  3242. cp $01 \ jp z,StoModule
  3243. cp $3A \ jr z,StoFloat
  3244. cp $2C \ jr nz,NotOSVar
  3245. ;Save Grammer's Ans
  3246. push bc
  3247. ;Make sure it is a valid name
  3248. ld a,(hl)
  3249. cp 72h ;Ans
  3250. jr z,+_
  3251. cp 'A'
  3252. jp c,ErrBadTOken
  3253. cp 'Z'+2
  3254. jp nc,ErrBadTOken
  3255. _:
  3256. ;It is valid, so update parsePtr
  3257. inc hl
  3258. ld (parsePtr),hl
  3259. ;Now write the name to OP1
  3260. ld (OP1+1),a
  3261. ld hl,0
  3262. ld (OP1+2),hl
  3263. ;Convert BC to a float in OP2
  3264. ld h,b
  3265. ld l,c
  3266. bcall(_SetXXXXOP2)
  3267. ;Find the var
  3268. rst rFindSym
  3269. jr c,create_OS_real
  3270. ;If it is a non-real, delete it and create it as a real var
  3271. and $1F
  3272. jr nz,delete_create_OS_real
  3273. ;If it is archived, just delete it and start anew
  3274. or b
  3275. jr z,sto_real
  3276. delete_create_OS_real:
  3277. bcall(_DelVarArc)
  3278. create_OS_real:
  3279. bcall(_CreateReal)
  3280. sto_real:
  3281. ;Copy OP2 to the number
  3282. ld hl,OP2
  3283. call mov9
  3284. ;restore Grammer's Ans
  3285. pop bc
  3286. ret
  3287. NotAVar:
  3288. ld (parsePtr),hl
  3289. ret
  3290. StoFloat:
  3291. ld a,(hl)
  3292. call VarP
  3293. jr nc,NotAVar
  3294. ld (parsePtr),de
  3295. ld e,(hl)
  3296. inc hl
  3297. ld d,(hl)
  3298. ld h,b
  3299. ld l,c
  3300. jp mov4_page0
  3301. NotOSVar:
  3302. call VarP
  3303. jr nc,NotAVar
  3304. push hl
  3305. push bc
  3306. ld bc,stack_base
  3307. or a
  3308. sbc hl,bc
  3309. add hl,bc
  3310. pop bc
  3311. jr nz,+_
  3312. ld (stack_ptr),bc
  3313. _:
  3314. ld a,(de)
  3315. ex de,hl
  3316. inc hl
  3317. call VarP
  3318. jr c,+_
  3319. dec hl
  3320. ex de,hl \ pop hl
  3321. _:
  3322. ld (hl),c
  3323. inc hl
  3324. ld (hl),b
  3325. ld (parsePtr),de
  3326. ret nc
  3327. pop hl
  3328. ld de,(ThetaPrimeVar)
  3329. ld (hl),e
  3330. inc hl
  3331. ld (hl),d
  3332. ret
  3333. StoModule:
  3334. inc hl
  3335. ld (parsePtr),hl
  3336. ld hl,module_count
  3337. ld a,(hl)
  3338. cp 5
  3339. jp nc,ErrPkgNotFound
  3340. ;now should verify the module
  3341. inc (hl)
  3342. adc a,a
  3343. add a,l
  3344. ld l,a
  3345. ld (hl),c
  3346. inc hl
  3347. ld (hl),b
  3348. ;Check if BC points to the name of a valid module.
  3349. call GetVarName_BC
  3350. call GetVarInfo_
  3351. jp c,module_not_found
  3352. call GetVarInfoVarFound
  3353. push hl
  3354. ld hl,verify_package
  3355. ld (next_page_call_address),hl
  3356. pop hl
  3357. call next_page_call
  3358. ret nc
  3359. jp module_not_found
  3360. StoInput:
  3361. ld a,(hl)
  3362. cp $AE
  3363. jr z,sto_input_size
  3364. ld (parsePtr),hl
  3365. ld (input_base),bc
  3366. ret
  3367. sto_input_size:
  3368. inc hl
  3369. ld (parsePtr),hl
  3370. ld (input_size),bc
  3371. ret
  3372. Return:
  3373. call EndOfLine
  3374. ld c,l
  3375. ld b,h
  3376. ret
  3377. GotoToken:
  3378. push bc
  3379. call ParseFullArg
  3380. ld (parsePtr),bc
  3381. pop bc
  3382. ret
  3383. DispGraph:
  3384. ld a,(hl)
  3385. call EndOArg
  3386. call nz,isop
  3387. jp z,GraphToLCD
  3388. call ParseFullArg
  3389. ld h,b
  3390. ld l,c
  3391. ld ixh,b
  3392. ld ixl,c
  3393. jp BufferToLCD
  3394. EndOArg:
  3395. cp 4 \ ret z ;->
  3396. EndOArgNotSto:
  3397. cp 2Bh \ ret z ;,
  3398. EndOfLine_newcol:
  3399. cp 3Fh \ ret z ;NL
  3400. ; cp 3Ah \ ret z
  3401. cp 3Eh \ ret z ;:
  3402. or a
  3403. ret
  3404. isop:
  3405. cp $82 ;*
  3406. ret z
  3407. cp $83 ;/
  3408. ret z
  3409. cp $95 ; nCr
  3410. cp 1 ;>Frac
  3411. ret z
  3412. cp 2 ;>Dec
  3413. ret z
  3414. cp $6A
  3415. ret c
  3416. cp $72
  3417. jr nc,+_
  3418. cp a
  3419. ret
  3420. _:
  3421. or a
  3422. ret
  3423. ;===============================================================
  3424. FindEndToken:
  3425. ;===============================================================
  3426. ;Input:
  3427. ; HL is an address
  3428. ;Outputs:
  3429. ; HL points to the byte after the proper End token
  3430. ;===============================================================
  3431. ld b,0
  3432. SearchEnd_inc:
  3433. inc b
  3434. SearchEndLoop:
  3435. inc hl
  3436. ld a,(hl)
  3437. ; Make sure it isn't >Nom(
  3438. cp $BB
  3439. jr nz,+_
  3440. inc hl
  3441. ld a,(hl)
  3442. cp 5
  3443. jr z,SearchEnd_inc
  3444. jr SearchEndLoop
  3445. _:
  3446. call Is_2_Byte
  3447. jr nz,+_
  3448. inc hl
  3449. jr SearchEndLoop
  3450. _:
  3451. ld a,(hl)
  3452. sub $CF ;Then
  3453. jr c,SearchEndLoop ;**Just to save time
  3454. jr z,SearchEnd_inc
  3455. dec a
  3456. dec a \ jr z,SearchEnd_inc ;While
  3457. dec a \ jr z,SearchEnd_inc ;Repeat
  3458. dec a \ jr z,SearchEnd_inc ;For
  3459. dec a \ jr nz,SearchEndLoop ;End
  3460. djnz SearchEndLoop
  3461. inc hl
  3462. ret
  3463. FindElseEnd:
  3464. ;Input:
  3465. ; HL is an address
  3466. ;Outputs:
  3467. ; HL points to the byte after the proper Else or End token
  3468. ; A is the last token checked
  3469. ld b,0
  3470. FindElseEnd_:
  3471. inc b
  3472. FindElseEndLoop:
  3473. inc hl
  3474. ld a,(hl)
  3475. ; Make sure it isn't >Nom(
  3476. cp $BB
  3477. jr nz,+_
  3478. inc hl
  3479. ld a,(hl)
  3480. cp 5
  3481. jr z,FindElseEnd_
  3482. jr FindElseEndLoop
  3483. _:
  3484. call Is_2_Byte
  3485. jr nz,+_
  3486. inc hl
  3487. jr FindElseEndLoop
  3488. _:
  3489. ld a,(hl)
  3490. sub $CF ;Then
  3491. jr c,FindElseEndLoop
  3492. jr z,FindElseEnd_ ;Then
  3493. dec a \ jr z,check_else
  3494. dec a \ jr z,FindElseEnd_ ;While
  3495. dec a \ jr z,FindElseEnd_ ;Repeat
  3496. dec a \ jr z,FindElseEnd_ ;For
  3497. dec a \ jr nz,FindElseEndLoop
  3498. _:
  3499. djnz FindElseEndLoop
  3500. ld a,(hl)
  3501. inc hl
  3502. ret
  3503. check_else:
  3504. ;If this isn't THE `Else`, then we don't want to decrement the counter
  3505. djnz FindElseEnd_
  3506. ld a,(hl)
  3507. inc hl
  3508. ret
  3509. ;===============================================================
  3510. GetGrammerText:
  3511. ;===============================================================
  3512. ;Input:
  3513. ; HL points to the start of the string
  3514. ;Outputs:
  3515. ; A is the value of the ending byte of the string
  3516. ; BC is the size of the string
  3517. ; DE points to the start of the converted string
  3518. ; HL points to the ending byte of the string
  3519. ; z flag is set
  3520. ;===============================================================
  3521. ld de,saveSScreen
  3522. GetGrammerText_DE:
  3523. ld bc,0
  3524. push de
  3525. TextConvert:
  3526. ld a,(hl)
  3527. cp 4 ;->
  3528. jr z,TextConvertEnd
  3529. cp 3Fh ;newline
  3530. jr z,TextConvertEnd
  3531. cp 2Ah ;"
  3532. jr z,TextConvertEnd
  3533. call TokToASCII+3
  3534. jp TextConvert
  3535. ld de,OP3
  3536. TokToASCII:
  3537. ;Inputs:
  3538. ; HL points to the token
  3539. ; DE points to where the token should get converted to
  3540. ;Outputs:
  3541. ; HL is incremented
  3542. ; DE points to the byte after the string
  3543. ; BC is the size of the string
  3544. ld bc,0
  3545. push hl
  3546. push bc
  3547. push de
  3548. bcall(_Get_Tok_Strng)
  3549. pop de
  3550. pop hl
  3551. add hl,bc
  3552. push hl
  3553. ld hl,OP3
  3554. ldir
  3555. pop bc
  3556. pop hl
  3557. ld a,(hl)
  3558. call Is_2_Byte
  3559. inc hl
  3560. ret nz
  3561. inc hl
  3562. ret
  3563. TextConvertEnd:
  3564. inc hl
  3565. pop de
  3566. ret
  3567. ;===============================================================
  3568. GetGrammerStr:
  3569. ;===============================================================
  3570. ;Input:
  3571. ; HL points to the start of the string
  3572. ;Outputs:
  3573. ; A is the value of the ending byte of the string
  3574. ; BC is the size of the string
  3575. ; HL points to the ending byte of the string
  3576. ; z flag is set
  3577. ;===============================================================
  3578. ld bc,-1
  3579. ; inc hl
  3580. _:
  3581. ld a,(hl)
  3582. inc bc
  3583. or a \ ret z
  3584. cp 4 \ ret z
  3585. cp 3Fh \ ret z
  3586. inc hl
  3587. cp 2Ah \ jr nz,-_
  3588. ret
  3589. VarP:
  3590. cp $AF ;? token
  3591. jr nz,VarPointer
  3592. ex de,hl
  3593. scf
  3594. ld hl,qmarkVar
  3595. ret
  3596. ;===============================================================
  3597. VarPointer:
  3598. ;===============================================================
  3599. ;Inputs:
  3600. ; A is the var to return the pointer of
  3601. ; hl points to the next byte
  3602. ;Outputs:
  3603. ; A is the lower 8-bits of the pointer
  3604. ; BC is not affected
  3605. ; DE should be used to update (parsePtr)
  3606. ; HL points to the var data
  3607. ; c flag is reset if A was not a var token
  3608. cp $BB
  3609. jr nz,NotBBvar
  3610. ld d,h
  3611. ld e,l
  3612. ld a,(hl)
  3613. cp $4B ;Pmt_End
  3614. jr z,Pmt_End_ptr
  3615. cp $4C ;Pmt_Bgn
  3616. jr z,Pmt_Bgn_ptr
  3617. sub 203
  3618. ret nc
  3619. sub -16
  3620. adc a,10
  3621. cp 26
  3622. ret nc
  3623. add a,a
  3624. ld hl,pvars+54
  3625. add a,l
  3626. ld l,a
  3627. #if (pvars+54)&255>=204
  3628. jr nc,+_
  3629. inc h
  3630. _:
  3631. #endif
  3632. inc de
  3633. scf
  3634. ret
  3635. Pmt_End_ptr:
  3636. ld hl,stack_top
  3637. inc de
  3638. scf
  3639. ret
  3640. Pmt_Bgn_ptr:
  3641. ld hl,stack_base
  3642. inc de
  3643. scf
  3644. ret
  3645. NotBBVar:
  3646. cp 'A'
  3647. ccf
  3648. ret nc
  3649. cp 'Z'+2
  3650. ret nc
  3651. sub 'A'
  3652. rlca
  3653. ld d,pvars>>8
  3654. ld e,a
  3655. ld a,(hl)
  3656. cp $AE
  3657. jr nz,+_
  3658. ld a,54
  3659. add a,e
  3660. ld e,a
  3661. inc hl
  3662. _:
  3663. ld a,e
  3664. add a,pvars&255
  3665. ld e,a
  3666. #if pvars&255>=202
  3667. jr nc,+_
  3668. inc d
  3669. _:
  3670. #endif
  3671. ex de,hl
  3672. scf
  3673. ret
  3674. ;===============================================================
  3675. EndOfLine:
  3676. ;===============================================================
  3677. ;Input:
  3678. ; HL is a pointer
  3679. ;Output:
  3680. ; HL points to the next line
  3681. ;===============================================================
  3682. ld a,3Fh
  3683. push bc
  3684. ld bc,0
  3685. cpir
  3686. pop bc
  3687. ret
  3688. ;===============================================================
  3689. IsHexTok:
  3690. ;===============================================================
  3691. ;Input:
  3692. ; DE points to the byte
  3693. ;Output:
  3694. ; DE is incremented by 1
  3695. ; A is the hex value if A is a hex token
  3696. ; nc if A is a hex token
  3697. ; c if A is not a hex token
  3698. ;===============================================================
  3699. ld a,(de)
  3700. inc de
  3701. cp 47h
  3702. ccf
  3703. ret c
  3704. cp 'A'
  3705. jr nc,+_
  3706. cp 3Ah
  3707. ccf
  3708. ret c
  3709. .db $DA ;start of jp c,**
  3710. _:
  3711. sub 7
  3712. sub 30h
  3713. ret
  3714. ;===============================================================
  3715. ConvRStr:
  3716. ;===============================================================
  3717. ;Input:
  3718. ; DE points to the base 10 number string in RAM.
  3719. ;Outputs:
  3720. ; HL is the 16-bit value of the number
  3721. ; DE points to the byte after the number
  3722. ; BC is HL/10
  3723. ; z flag reset (nz)
  3724. ; c flag reset (nc)
  3725. ;Destroys:
  3726. ; A (actually, add 30h and you get the ending token)
  3727. ;Size: 41 bytes
  3728. ;Speed: 134+(106+{0,9})n
  3729. ; n is the number of digits
  3730. ; c is at most n-2
  3731. ; at most 691 cycles for any 16-bit decimal value
  3732. ;===============================================================
  3733. dec hl
  3734. bit baseInput,(iy+UserFlags)
  3735. jp nz,ConvHexStr
  3736. bit floatmode,(iy+ModeFlags2)
  3737. jr nz,ConvRStr_Float
  3738. ex de,hl
  3739. ld hl,0
  3740. push de ;save in case we encounter a float
  3741. _:
  3742. ld a,(de)
  3743. sub 30h
  3744. cp 10
  3745. jr nc,+_
  3746. inc de
  3747. ld b,h
  3748. ld c,l
  3749. add hl,hl
  3750. add hl,hl
  3751. add hl,bc
  3752. add hl,hl
  3753. add a,l
  3754. ld l,a
  3755. jr nc,-_
  3756. inc h
  3757. jp -_
  3758. _:
  3759. jr z,+_ ;means it was a decimal point
  3760. pop bc
  3761. ld (parsePtr),de
  3762. ld b,h
  3763. ld c,l
  3764. ret
  3765. _:
  3766. pop hl
  3767. ConvRStr_Float:
  3768. ;HL points to the string
  3769. dec hl
  3770. ld a,(hl)
  3771. cp $B0 ;neg sign token
  3772. jr nz,+_
  3773. ;Need to pop off the return address; not returning to the neg routine
  3774. pop de
  3775. pop de
  3776. .db $FE ;start of cp *, causes the inc hl to be ignored
  3777. _:
  3778. inc hl
  3779. ;HL points to the float
  3780. push hl
  3781. call floatstackpush
  3782. ld b,h
  3783. ld c,l
  3784. ld hl,str2single
  3785. ld (next_page_call_address),hl
  3786. pop hl
  3787. call next_page_call
  3788. ld hl,(ptr_sto)
  3789. ld (parsePtr),hl
  3790. ret
  3791. SetMem:
  3792. ld (hl),a
  3793. ld d,h
  3794. ld e,l
  3795. cpi
  3796. ret po
  3797. ex de,hl
  3798. ldir
  3799. ret
  3800. ;===============================================================
  3801. Is_2_Byte:
  3802. ;===============================================================
  3803. cp $EF \ ret z
  3804. cp $BB \ ret z
  3805. cp $7E \ ret z
  3806. Is_Var_Name:
  3807. sub $AA \ ret z ;AA
  3808. add a,$47 \ ret z ;63
  3809. inc a \ ret z
  3810. inc a \ ret z
  3811. inc a \ ret z
  3812. add a,2 \ ret z
  3813. inc a \ ret z
  3814. inc a \ ret
  3815. ConvHexTo86ECh:
  3816. ;max: 174n+91
  3817. ;min: 128n+56
  3818. ;avg: 145.25x+79 (typical avg, assuming most end in newline)
  3819. ;An 8x8 sprite is now 6% faster on avg. than versions <2.50
  3820. ld d,b
  3821. ld e,c
  3822. ld hl,86ECh
  3823. ld bc,$0A30
  3824. ConvHexLoop7:
  3825. ; HL points to where to convert
  3826. ; DE is where to convert from
  3827. ld a,(de)
  3828. inc de
  3829. sub c
  3830. ret c
  3831. cp b
  3832. jr c,+_
  3833. sub 17
  3834. ret c
  3835. cp 6
  3836. ret nc
  3837. add a,b
  3838. _:
  3839. rld
  3840. ld a,(de)
  3841. inc de
  3842. sub c
  3843. ret c
  3844. cp b
  3845. jr c,+_
  3846. sub 17
  3847. ret c
  3848. cp 6
  3849. ret nc
  3850. add a,b
  3851. _:
  3852. rld
  3853. inc hl
  3854. jp ConvHexLoop7
  3855. IsConditional:
  3856. cp $D8 \ ret z ;pause
  3857. cp $CE \ ret z ;if
  3858. cp $D1 \ ret z ;while
  3859. cp $D2 \ ret ;repeat
  3860. EraseParticle:
  3861. ld c,(hl)
  3862. inc hl
  3863. ld b,(hl)
  3864. ;pixel off
  3865. push bc
  3866. call GetPixelLoc
  3867. pop bc
  3868. ret
  3869. isStartMenu_valid:
  3870. ld a,(OP1+1)
  3871. cp $23
  3872. jr z,StartMenu_invalid
  3873. cp $21
  3874. jr z,StartMenu_invalid
  3875. ld hl,(VATPtr)
  3876. ld a,(hl)
  3877. cp 1 ;don't want lists
  3878. jr nz,+_
  3879. StartMenu_invalid:
  3880. or a
  3881. ret
  3882. _:
  3883. cp 13 ;don't want complex lists
  3884. jr z,StartMenu_invalid
  3885. cp 17h ;don't want GroupVars
  3886. jr z,StartMenu_invalid
  3887. bit 6,(iy+UserFlags) ;must be AppV
  3888. jr z,+_
  3889. cp 15h
  3890. ret nz
  3891. _:
  3892. ;need to pull in six bytes
  3893. #ifdef include_LoadTSA
  3894. call LoadReadArc
  3895. #endif
  3896. ld bc,-3
  3897. add hl,bc
  3898. ld e,(hl)
  3899. dec hl
  3900. ld d,(hl)
  3901. dec hl
  3902. ld a,(hl)
  3903. or a
  3904. jr z,+_
  3905. ld b,a
  3906. dec hl
  3907. ld a,(hl)
  3908. add a,10
  3909. add a,e
  3910. ld e,a
  3911. ld a,b
  3912. jr nc,+_
  3913. inc d
  3914. jp po,+_
  3915. inc a
  3916. ld d,$40
  3917. _:
  3918. ex de,hl
  3919. ld de,cmdShadow
  3920. ld bc,2
  3921. call ReadArc
  3922. ld bc,(cmdShadow)
  3923. ;need to save A:HL, BC
  3924. ld (TempWord3),a
  3925. ld (TempWord4),bc
  3926. ld (TempWord5),hl
  3927. _:
  3928. ld bc,4
  3929. call ReadArc
  3930. ld hl,cmdShadow+2
  3931. bit OnBlockFlag,(iy+UserFlags) ;ASM only
  3932. jp nz,asm_header_only
  3933. ;non-ASM and ASM alike
  3934. bit baseInput,(iy+UserFlags)
  3935. ret z ;doesn't have any special filters
  3936. ;must be a Grammer Var
  3937. ;header is either $BB,$6D,$55,$C9 or $3A,$30,$3E
  3938. ld a,(hl) \ cp $BB \ jr z,+_
  3939. cp $3A \ ret nz
  3940. inc hl \ ld a,(hl) \ cp $30 \ ret nz
  3941. inc hl \ ld a,(hl) \ cp $3E \ ret
  3942. _:
  3943. inc hl \ ld a,(hl) \ cp $6D \ ret nz
  3944. inc hl \ ld a,(hl) \ cp $55 \ ret nz
  3945. inc hl \ ld a,(hl) \ cp $C9
  3946. ret
  3947. asm_header_only:
  3948. ;first two bytes must be $BB,$6D
  3949. ;
  3950. ld a,(hl) \ cp $BB \ ret nz
  3951. inc hl \ ld a,(hl) \ cp $6D \ ret nz
  3952. bit baseInput,(iy+UserFlags)
  3953. ret z
  3954. ;next two bytes must be $55,$C9
  3955. ;
  3956. inc hl \ ld a,(hl) \ cp $55 \ ret nz
  3957. inc hl \ ld a,(hl) \ cp $C9
  3958. ret
  3959. #ifdef include_LoadTSA
  3960. ReadArc:
  3961. call LoadReadArc
  3962. jp TSA
  3963. #else
  3964. ReadArc = TSA
  3965. #endif
  3966. ReadArcData:
  3967. #ifdef include_loadTSA
  3968. .dw ReadArcEnd-ReadArc-2
  3969. #endif
  3970. #include "readarc.z80"
  3971. ReadArcEnd:
  3972. FindGVarData:
  3973. ld hl,GVarData
  3974. rst rMov9ToOP1
  3975. bcall(_ChkFindSym)
  3976. ret nc
  3977. ld hl,3
  3978. bcall(_CreateAppVar)
  3979. ret
  3980. GetVarName:
  3981. call ParseFullArg
  3982. GetVarName_BC:
  3983. ld h,b
  3984. ld l,c
  3985. GetVarName_:
  3986. ld a,(hl)
  3987. and 1Fh
  3988. ld de,OP1
  3989. sub 5 \ jp z,GetGrammerText_DE
  3990. dec a \ jp z,GetGrammerText_DE
  3991. sub 15 \ jp z,GetGrammerText_DE
  3992. dec a \ jp z,GetGrammerText_DE
  3993. ld bc,3
  3994. ld d,h \ ld e,l
  3995. add hl,bc
  3996. cp a
  3997. ret
  3998. GetVarInfo:
  3999. ;Returns name in OP1
  4000. ;A is the flashpage
  4001. ;HL points to SymEntry
  4002. ;DE points to size bytes
  4003. ;BC is the length of the name (for use when finding archived data)
  4004. ;nc if it exists
  4005. ;z if it is in RAM
  4006. call GetVarName
  4007. GetVarInfo_:
  4008. ex de,hl
  4009. ld de,OP1
  4010. push bc
  4011. ldir
  4012. xor a
  4013. ld (de),a
  4014. bcall(_ChkFindSym)
  4015. ld a,b
  4016. pop bc
  4017. ret c
  4018. or a
  4019. ret
  4020. GetvarInfo2:
  4021. ;Inputs:
  4022. ; The next argument to parse points to the name of the var to get info about
  4023. ;Outputs:
  4024. ; A is the ending page (start of data)
  4025. ; BC is the size of the var
  4026. ; DE points to the SymEntry
  4027. ; HL points to the data
  4028. ; c is set if the var does not exist
  4029. #ifdef include_LoadTSA
  4030. call LoadReadArc
  4031. #endif
  4032. call GetVarInfo
  4033. ret c
  4034. GetVarInfoVarFound:
  4035. ex de,hl
  4036. or a
  4037. jr nz,+_
  4038. ld c,(hl) \ inc hl
  4039. ld b,(hl) \ inc hl
  4040. ret
  4041. _:
  4042. add hl,bc
  4043. ld c,9
  4044. add hl,bc
  4045. bit 7,h
  4046. jr z,+_
  4047. ld h,40h
  4048. inc a
  4049. _:
  4050. push de
  4051. ld de,OP2
  4052. ld bc,2
  4053. call ReadArc
  4054. ld bc,(OP2)
  4055. pop de
  4056. or a
  4057. ret
  4058. GPutSI:
  4059. ; The string to display immediately follows the call
  4060. ; The string is zero terminated
  4061. ;Outputs:
  4062. ; All registers are preserved
  4063. ex (sp),hl
  4064. push de
  4065. push bc
  4066. push af
  4067. call GPutS
  4068. pop af
  4069. pop bc
  4070. pop de
  4071. ex (sp),hl
  4072. ret
  4073. DrawRectToGraphI:
  4074. ex (sp),hl
  4075. ; push de \ push bc \ push af
  4076. ld e,(hl) \ inc hl
  4077. ld c,(hl) \ inc hl
  4078. ld b,(hl) \ inc hl
  4079. ld d,(hl) \ inc hl
  4080. ld a,(hl) \ inc hl
  4081. ex (sp),hl
  4082. jp DrawRectToGraph
  4083. ExecLine_:
  4084. ld a,(hl)
  4085. inc hl
  4086. call VarP
  4087. ret nc
  4088. parse_by_ptr_to_ptr:
  4089. push de
  4090. push hl
  4091. ld a,(hl)
  4092. inc hl
  4093. ld h,(hl)
  4094. ld l,a
  4095. call ParseNextFullArg_HL
  4096. ld de,(parsePtr)
  4097. pop hl
  4098. inc de
  4099. ld (hl),e
  4100. inc hl
  4101. ld (hl),d
  4102. pop hl
  4103. ld (parsePtr),hl
  4104. ret
  4105. ExecLine:
  4106. call ParseFullArg
  4107. push bc
  4108. cp 2Bh
  4109. ld bc,(ProgStart)
  4110. call z,ParseNextFullArg
  4111. push bc
  4112. ld bc,32768
  4113. cp 2Bh
  4114. call z,ParseNextFullArg
  4115. push bc
  4116. cp 2Bh
  4117. ld bc,63
  4118. call z,ParseNextFullArg
  4119. ld a,c
  4120. pop bc
  4121. pop hl
  4122. pop de
  4123. call SearchLine_00
  4124. ld b,d
  4125. ld c,e
  4126. jp g_expr
  4127. Byte:
  4128. ld b,0
  4129. ld c,(hl)
  4130. inc hl
  4131. ld (parsePtr),hl
  4132. ret
  4133. Word:
  4134. ld c,(hl)
  4135. inc hl
  4136. ld b,(hl)
  4137. inc hl
  4138. ld (parsePtr),hl
  4139. ret
  4140. NegRelPtr:
  4141. ld c,(hl)
  4142. inc hl
  4143. ld b,(hl)
  4144. inc hl
  4145. ld (parsePtr),hl
  4146. ld hl,(progEnd)
  4147. or a
  4148. sbc hl,bc
  4149. ld b,h
  4150. ld c,l
  4151. ret
  4152. Base2Num:
  4153. ld bc,0
  4154. ld d,b
  4155. ld e,c
  4156. _:
  4157. ld a,(hl)
  4158. sub '2'
  4159. add a,2
  4160. jr nc,+_
  4161. rrca
  4162. rl c
  4163. rl b
  4164. rl e
  4165. rl d
  4166. inc hl
  4167. jp -_ ;It saves 2 cycles using JP D:
  4168. _:
  4169. set FactorialFlag,(iy+InternalFlag)
  4170. ld (parsePtr),hl
  4171. ret
  4172. _:
  4173. ld hl,lnSingle
  4174. jp float_stepin_1
  4175. LnToken:
  4176. ld a,(hl)
  4177. cp 3Ah
  4178. jr z,-_
  4179. cp $B0
  4180. push bc
  4181. jr z,JumpBack
  4182. call ParseFullArg
  4183. dec bc
  4184. inc b
  4185. inc c
  4186. ld d,b \ ld e,c
  4187. ld bc,0
  4188. _:
  4189. ld a,3Fh
  4190. cpir
  4191. dec e
  4192. jr nz,-_
  4193. dec d
  4194. jr nz,-_
  4195. ld (parsePtr),hl
  4196. pop bc
  4197. ret
  4198. JumpBack:
  4199. call ParseNextFullArg
  4200. inc b
  4201. inc c
  4202. ld d,b \ ld e,c
  4203. dec hl
  4204. ld bc,0
  4205. _:
  4206. ld a,3Fh
  4207. cpdr
  4208. dec e
  4209. jr nz,-_
  4210. dec d
  4211. jr nz,-_
  4212. ld (parsePtr),hl
  4213. pop bc
  4214. ret
  4215. cmdJmp:
  4216. #ifdef ALIGN_COMMAND_TABLE
  4217. ld h,CommandJumpTable>>8
  4218. add a,a
  4219. jr nc,+_
  4220. inc h
  4221. _:
  4222. ld l,a
  4223. #else
  4224. ld hl,CommandJumpTable
  4225. add a,a
  4226. jr nc,+_
  4227. inc h
  4228. _:
  4229. add a,l
  4230. ld l,a
  4231. jr nc,+_
  4232. inc h
  4233. _:
  4234. #endif
  4235. ld a,(hl)
  4236. inc hl
  4237. ld h,(hl)
  4238. ld l,a
  4239. push hl
  4240. ld hl,(parsePtr)
  4241. ret
  4242. menu:
  4243. ld hl,menu_code_start
  4244. ld (next_page_call_address),hl
  4245. jp next_page_call
  4246. pushvars_00:
  4247. ld de,pushvars
  4248. ld (next_page_call_address),de
  4249. jp next_page_call
  4250. FracToken_00:
  4251. ld de,FracToken
  4252. ld (next_page_call_address),de
  4253. jp next_page_call
  4254. ParamToken_00:
  4255. ld de,ParamToken
  4256. ld (next_page_call_address),de
  4257. jp next_page_call
  4258. LblToken:
  4259. ld hl,LblToken_01
  4260. ld (next_page_call_address),hl
  4261. jp next_page_call
  4262. FS_createvar_max:
  4263. push hl
  4264. ld hl,FS_createvar_max_01
  4265. jr jp_next_page_call
  4266. FS_delvar:
  4267. push hl
  4268. ld hl,FS_delvar_01
  4269. jr jp_next_page_call
  4270. FS_resize:
  4271. push hl
  4272. ld hl,FS_resize_01
  4273. jr jp_next_page_call
  4274. FS_findvar:
  4275. push hl
  4276. ld hl,FS_findvar_01
  4277. jr jp_next_page_call
  4278. SearchString:
  4279. push hl
  4280. ld hl,searchstring_routine
  4281. jr jp_next_page_call
  4282. SearchLine_00:
  4283. push hl
  4284. ld hl,SearchLine
  4285. jr jp_next_page_call
  4286. DrawRectToGraph:
  4287. push hl
  4288. ld hl,drawrect
  4289. jp_next_page_call:
  4290. ld (next_page_call_address),hl
  4291. pop hl
  4292. jp next_page_call
  4293. DegreeToken:
  4294. call ParseFullArg
  4295. ld (gbuf_temp),bc
  4296. inc hl
  4297. jp ParseArg2
  4298. todectoken:
  4299. ;Takes a pointer to a string and converts it to a float
  4300. ld hl,str2single
  4301. ld (next_page_call_address),hl
  4302. push bc
  4303. call floatstackpush
  4304. ld b,h
  4305. ld c,l
  4306. pop hl
  4307. jp next_page_call
  4308. InputToken:
  4309. ld de,s_null
  4310. ld a,(hl)
  4311. call EndOArg
  4312. call nz,isop
  4313. jr z,+_
  4314. call ParseFullArg
  4315. ld h,b
  4316. ld l,c
  4317. ld de,OP1
  4318. call GetGrammerText_DE
  4319. ld h,b
  4320. ld l,c
  4321. add hl,de
  4322. ld (hl),0
  4323. _:
  4324. ld hl,input
  4325. ld (next_page_call_address),hl
  4326. call next_page_call
  4327. ld b,h
  4328. ld c,l
  4329. ret
  4330. GraphToLCD:
  4331. ld hl,GraphToLCD_
  4332. ld (next_page_call_address),hl
  4333. jp next_page_call
  4334. BufferToLCD:
  4335. ld ix,BufferToLCD_
  4336. ld (next_page_call_address),ix
  4337. jp next_page_call
  4338. #include "main.z80"
  4339. #include "module.z80"
  4340. #include "ramcode.z80"
  4341. #include "routines.z80"
  4342. #include "SetUpData.z80"
  4343. #include "parserhook.z80"
  4344. #include "cmd/particle.z80"
  4345. #ifdef include_LoadTSA
  4346. #include "cmd/loadtsa.z80"
  4347. #endif
  4348. #include "gfx/text.z80"
  4349. #include "gfx/getpixelloc_nobound.z80"
  4350. #include "gfx/GetPixelLoc.z80"
  4351. #include "gfx/TileMap1.z80"
  4352. #include "math/mul16.z80"
  4353. #include "math/HL_Div_C.z80"
  4354. #include "math/DEHL_Div_C.z80"
  4355. #include "math/HL_Div_BC.z80"
  4356. #include "subroutines/getbyte.z80"
  4357. #include "grammerdata.z80"
  4358. #include "math.z80"
  4359. #include "subroutines/chardim.z80"
  4360. #include "subroutines/ConvOP1.z80"
  4361. #include "parserinterrupt.z80"
  4362. #include "err.z80"
  4363. #include "commandtable.z80"
  4364. .echo "Page 0: ",$8000-$," bytes remaining"
  4365. #if $>$8000
  4366. .error "ERR!! Page 1 is over by ",$-$8000," bytes!"
  4367. #else
  4368. .fill $8000-$,255
  4369. #endif
  4370. #include "01.z80"
  4371. .echo "RamCode : ",RamCodeEnd-RamCodeStart