grammer.z80 70 KB

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