grammer.z80 70 KB

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