grammer.z80 69 KB

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