Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .nolist
  2.     #include    "ti83plus.inc"
  3.     ;#DEFINE     PenCol= penrow +1
  4. .list
  5. .org    $9D93
  6. .db    t2ByteTok, tAsmCmp
  7.  
  8. stackpointer: .dw 0,0
  9.  
  10.  
  11. ;=================PROGRAM START====================================
  12.     DI
  13.     LD (stackpointer), SP
  14.  
  15.  
  16. main:
  17. .db "main",0
  18. ;load size_string table
  19. ;load class_string table
  20. ;load race_file
  21. ;   jp main
  22.     LD HL, main
  23.     call print_wait
  24.     LD HL, main
  25.     LD A, $20
  26.     LD  (HL), A
  27.     LD DE, sizeStrTab    ;null pointer for table
  28.     LD  HL, sizeStrTabName ;file_name
  29.     call LoadGenTable   ;initialize the size_string table
  30.     LD   DE, classStrTab
  31.     LD   HL, classStrTabName
  32.     call LoadGenTable   ;initialize the class_string table
  33.     call LoadRaceFile   ;initialize the race file
  34.     ;;we now have all our source files loaded, time to start displaying them
  35.     call initRaceMenu
  36.     LD HL, quitstr
  37.     call print_wait
  38.     jp  quit
  39.  
  40.     ;call makeRaceMenu
  41.  
  42. ;open the file and validate
  43. ;=============================================================================================================================================    
  44. ;LOAD RACE FILE================================================================================================================================
  45. ;=============================================================================================================================================
  46. ;load the race file and validate it, store its info into static variables
  47. LoadRaceFile:
  48. .db "ldRaceFile",0
  49.     LD HL, LoadRaceFile
  50.     call print_wait
  51.     LD HL, racefilename
  52.     rst 20h          ;$20= rMov9ToOp1......load name into op1
  53.     b_call(_ChkFindSym)     ;lookup variable in op1
  54.     JP  c, raceNotFound
  55.     AND %00011111    ;race file datatype is in accumulator,  however, high 3 bits are garbage
  56.     CP  $15          ;check to make sure racefile is an  appvar, with appvar tok
  57.     JP  nz, raceCorrupt
  58.     XOR A            ;clear a
  59.     CP  B            ;B=0 means variable resides in RAM, if its not, then that's no good
  60.     JP  nz, raceCorrupt
  61.     EX  DE, HL
  62.     LD  (racefile), HL;HL points to first  byte of file
  63.     LD  A, $BE
  64.     CP  (HL)         ;Check for first half of teh header
  65.     JP  nz, raceCorrupt
  66.     LD  A, $EF
  67.     INC HL           ;header+1
  68.     CP  (HL)         ;Check second half of header
  69.     JP  nz, raceCorrupt
  70.     LD  D, (HL)      ;load the size word into DE
  71.     INC HL           ;hl=header+2
  72.     LD  E, (HL)      
  73.     INC HL           ;hl=header+3
  74.     LD (racefileSize), DE ;store it in little endian-ness        
  75.     LD  D, (HL)     ;DE points to table offsest, load the offset word into DE
  76.     INC HL          ;hl= header+4
  77.     LD  E, (HL)
  78.     INC HL          ;hl= header+5
  79.     LD  (raceTableOffset), DE  ;offset of race table from index now stored in little endianness
  80.  
  81.     ;now to make a pointer to the data table segment of the race file
  82.     LD  BC, (raceFile)
  83.     LD  H,C
  84.     LD  L,B         ;load  racefile pointer into HL, too bad its LITTLE ENDIAN
  85.     ADD HL, De      ;HL = raceFilePtr+offeset...points to beginning of DATA TABLE
  86.     LD (raceTablePointer), HL ;LITTLE ENDIAN
  87.     ret              ;return
  88.  
  89. ;=============================================================================================================================================    
  90. ;LOAD GENERAL TABLE FILE================================================================================================================================
  91. ;=============================================================================================================================================
  92. ;Load a general table of numbers of strings that starts with 0xf00d
  93. ;Stack Args- HL=pointer to filename
  94. ;            DE=where to store pointes
  95. ;note that registers change a lot here
  96. LoadGenTable:
  97.     PUSH HL
  98.     PUSH DE
  99.     rst 20h          ;$20= rMov9ToOp1......load name into op1
  100.     b_call(_ChkFindSym) ;lookup variable in op1, if found, CA=0; ACC= data_type_info; B=0 (if in ram); DE= pointer; HL= sym_table
  101.     POP HL           ;HL=where to put pointers, DE= pointer to Struct, STACK_TOP=pointer to filename
  102.     JP  c, genTabNotfound
  103.     AND %00011111 ;file's datatype is in accumulator,  however, high 3 bits are garbage
  104.     CP  $15          ;check to make sure file is an  appvar, with appvar tok
  105.     JP  nz, genTableCorrupt
  106.     XOR A            ;A=0
  107.     CP  B            ;B=0 means variable resides in RAM, if its not, then that's no good
  108.     JP  nz, genTableCorrupt
  109.     LD (HL),D       ;Store file Address......De points to first  byte of file, this instruction is a little premature, but whatever
  110.     INC HL          ;....
  111.     LD (HL),E       ;Address stored.
  112.     EX  DE,HL       ;HL points to first byte in file
  113.     LD  A, $F0      ;prepare to check header
  114.     CP  (HL)        ;Check for first half of teh header
  115.     JP  nz, genTableCorrupt
  116.     LD  A, $0D      ;load second check value
  117.     INC HL          ;point DE to next byte
  118.     CP  (HL)        ;Check second half of header
  119.     JP  nz, genTableCorrupt
  120.     POP HL          ;Return stack to normal, so we can return
  121.     RET
  122.  
  123.  
  124. ;=============================================================================================================================================    
  125. ;Display list of races================================================================================================================================
  126. ;=============================================================================================================================================
  127. ;;index format is (id)[offset) with each entery being 3 bytes long
  128. ;;
  129. initRaceMenu:
  130.     LD  A, 0   ;set currently selected  string index to zero
  131.     LD (m0index), A
  132. buildRaceMenu:
  133. .db "buildRaceMen",0
  134.     LD  HL, buildRaceMenu
  135.     call print_wait    
  136. ;   LD  A, (raceTablePointer) ;LD DE, (raceTablePointer) so we know when to stop
  137. ;   LD  E, A
  138. ;   LD  A, (raceTablePointer+1)
  139. ;   LD  D, A    ;DE = START OF TABLE
  140.     LD  A,  (racefile+1);load HL to START OF RACEFILE
  141.     LD  H, A
  142.     LD  A,  (racefile) ;load pointer to racefile
  143.     LD  L, A   ;HL = raceFile[0]
  144.     LD  B, 0
  145.     LD  C, 7
  146.     ADD HL,BC  ;HL = racefile[7]
  147. ;;HL points to Byte 2 of the index, the MSB of the offset of the first race_entery
  148.     LD  A,(m0index) ;the currently selected index will be the first item displayed on the list
  149.     LD  B, A
  150.     ADD A, B  
  151.     ADD A, B ; A= 3*oldA (this way when we add A to L, we are now offset the correct number of races to display)
  152.     LD  C, A
  153.     LD  B, 0   ;BC is the offset to the index address of first item to display
  154.     ADD HL,BC  ;HL points to dataTableOffset of first race we want to display, it will be assumed that on entering, this will never overshoot the end of the table
  155.     XOR A      ;
  156.     LD (it),A  ;reset the iteration count
  157.     LD  DE, sbuff0 ;prepare to enter the next segment
  158.     PUSH DE
  159.     call clearsbuff  ;REMOVED FOR DEBUGGING TEMPORARILY
  160.     POP DE
  161.  
  162. _BRML1:        ;the loop to load the race names onto the string table sbuff
  163.                ;on entery, HL= pointer to 2nd byte of the next race entery to be read from the index
  164.                ;           DE= next entery of sbuff
  165.  
  166.     nop            
  167. ;;;;;;;
  168. .db "_BRML1",0
  169.     push hl
  170.     LD HL, _BRML1
  171.     INC HL
  172.     call print_wait
  173.     pop HL
  174. ;;;;;;;;;;;;
  175. _BRML1b: ;;from now on, this little space needs to say what the rest of the section does
  176.     LD  B,(HL) ;B=msb of race_entery offset
  177.     INC HL
  178.     LD  C,(HL) ;C=lsb of race_entery offset
  179.     INC HL
  180.     INC HL
  181.     PUSH HL    ;stack = MSB of next race in index, BC= race_entery offset from start of race_table
  182.     LD  A,(raceTablePointer)
  183.     LD  L, A
  184.     LD  A,(raceTablePointer+1)
  185.     LD  H, A
  186.     ADD HL, BC ;HL points to first byte of race
  187.     LD  B,0
  188.     LD  C,2
  189.     ADD HL,BC  ;hl=first byte of Race NAME
  190.     LD  B,0
  191.     LD  C,8      ;8 reps
  192.     LDIR         ;copy race name into buffer
  193.     ;LD (DE), C   ;c= zero because loop is over, so append a NULL to the end of the stirng sbuff[n][9]
  194.     INC DE       ;point DE to the next row in SBUFF
  195.     LD  A,(it)
  196.     INC A
  197.     LD (it),A    ;increase the iteration count
  198.     POP HL       ;hl=next table index to read, even if we break, this fixes the stack
  199.     CP  8        ;check how many its we did
  200.     JP  Z, _BRML2;if we have looped 8 times, break
  201.     PUSH DE
  202.     LD  A, (raceTablePointer)
  203.     LD  E, A
  204.     LD  A, (raceTablePointer+1);
  205.     LD  D, A
  206.     CALL cpHL_DE ;make sure we haven't overshot the end of the index
  207.     POP DE
  208.     JP  C, _BRML1b;continue if we are still within the index, otherwise fall thorugh
  209.  
  210.  
  211.  
  212. _BRML2:  ;;sbuff now contains all the enteries to dispaly, prepare the rest of the data
  213. ;   jp _BMRL3;DEBUG LINE
  214. .db "_BRML2",0
  215.     push hl
  216.     LD HL, _BRML2
  217.     call print_wait
  218.     pop HL
  219.     ;;;//done with the error testing
  220. ;   push hl
  221. ;   ld hl, dbg1
  222. ;   call print_wait
  223. ;   pop hl
  224.     LD HL, raceFileName+1 ;hl points to string "Races"
  225.     LD B,0
  226.     LD C,6 ;for 5 chars + null
  227.     LD DE, string1
  228.     LDIR   ;copy "races",0 into string1
  229.     ;;now to set up teh flags for the menu to be displayed, B will be our flags cause it is 0 right now
  230.     SET 1,B; B is going to be our flags bye, byte 0 =[back], 1=[info] 2= [up], 3=[down]
  231.     LD A, (m0index);a = current index in the menu
  232.     CP 0
  233.     JP Z, _BMRL3;is the current index zero?
  234.     SET 2,B ;if there are previous options in the list, allow the [back] button to be enabled
  235. _BMRL3: ;COMMENT ME
  236. .db "_BRML3",0
  237.     push hl  ;what is HL?
  238.     LD HL, _BMRL3
  239.     call print_wait
  240.     pop HL
  241.     ;;we want to find out if there are more strings below the first one to be displayed
  242.     ;LD  C, A  ;save a
  243.     LD  A, (sbuff1) ;is the next item in the string index null (because sbuff0 is the current string, is sbuff1 cointains sth, we can scroll to it
  244.     OR  0
  245.     JP  Z, _BMRL4 ;if sbuff[1] ==null, leave b[3] as zero
  246.     SET 3, B
  247. _BMRL4: ;COMMENT ME
  248. .db "_BRML4",0
  249. ;   push hl[DEBUG DISABLED]  what was hl before?
  250.     LD HL, _BMRL4
  251.     call print_wait
  252.     LD HL, sbuff0
  253.     call print_wait ;;print contents of SBUFF0
  254. ;   pop HL   [DEBUG DISABLED]
  255.     call DispMenu ;sbuff has list of strings to display, s1 has title of menu, B has flags
  256. _BMRinput:
  257.     b_call(_GetKey)
  258.     CP $05  ;enter pressed
  259.     jr z,_BMRenter
  260. ;   CP $49  ;y= pressed
  261. ;   Jr z,_BMRyeq
  262.     CP $48  ;[window] presed
  263.     Jr z,_BMRwin
  264.     CP $5A  ;[trace] pressed
  265.     Jr z,_BMRtrace
  266.     CP $44  ;[graph] pressed
  267.     Jr z,_BMRgraph
  268. ;   CP $03  ;up pressed
  269. ;   Jr z,_BMRup
  270. ;   CP $04  ;down pressed
  271. ;   Jr z,_BMRdown
  272.     jr _BMRinput
  273.  
  274.     ;handle input
  275. _BMRwin: ;;info was pressed, spawn a new menu about this racce
  276.     LD HL, quitstr
  277.     call print_wait
  278.     jp quit
  279.     jp buildRaceMenu ;;we need to redisplay the menu once we are done
  280.  
  281. _BMRtrace: ;;up one item
  282.     LD  A, (m0index)
  283.     CP  0
  284.     Jr  Z, _BMRinput
  285.     INC A
  286.     LD (m0index), A
  287.     JP  buildRaceMenu
  288.  
  289. _BMRgraph: ;down one item
  290. ;we need to find out how many items are in the index
  291.     LD  A, (raceTableOffset)
  292.     LD  L, A
  293.     LD  A, (raceTableOffset+1) ;HL = how far crap is frm teh start of the race_File
  294.     LD  H, A
  295.     LD  C, 6
  296.     LD  B, 0   ;we want to subtract 6 from the offset of the racceTable
  297.     SCF
  298.     CCF ;reset carry flag just in case
  299.     SBC HL,BC ;;HL = the size of the index section
  300.     LD  D, 3   ;divide the index size by 3 (the size of each entery)
  301.     call Div_HL_D ;hl = numbre of enteries
  302.     LD  A, (m0index);get the currently selected menu item
  303.     CP  L  ;we shouldn't have more than 255 races
  304.     Jr  NC, _BMRinput ;if we are at the max index possible, go back
  305.     INC A
  306.     LD (m0index), A
  307.     JP  buildRaceMenu
  308.  
  309. _BMRenter: ;;still testing, so just quit if enter pressed
  310.     LD HL, quitstr
  311.     call print_wait
  312.     jp  quit
  313.  
  314.  
  315. ;=============================================================================================================================================    
  316. ;Display MENU================================================================================================================================
  317. ;=============================================================================================================================================
  318. ;IN: string1- title of menu
  319. ;    sbuff0 - first string of menu to display
  320. ;    B  -flags
  321. ;    c  -button set to use, currently unimplemented
  322. ;assumes all strings in sbuff are 8 chars+null
  323. DispMenu:
  324. .db "dispMenu",0
  325.     push hl
  326.     ld hl, DispMenu
  327.     call print_wait
  328.     pop hl
  329.     PUSH BC
  330.     b_call(_ClrLCDFull)
  331.     XOR A
  332.     LD (pencol),A
  333.     LD (pencol+1),A ;clear pen row/col
  334.     LD HL, string1
  335.     b_call(_VPutS) ;display  contents of string1
  336.     SET TextInverse, (IY + TextFlags) ;set reverse video on
  337.     LD H,10
  338.     LD L,10
  339.     LD (pencol),HL
  340.     LD HL, sbuff0;
  341.     b_call(_VPutS);display sbuff0
  342.     RES TextInverse, (IY + TextFlags)
  343.  
  344.     LD  D, 10
  345.     LD  E, 10
  346.     LD  B,8 ;Our counter
  347. _DML1: ;loop to display the rest of the menu, assumes BC points to prev pen col, HL points to next string to display
  348.     call cpHL_0 ;see if hl is null
  349.     JP z, _DML2 ;if null, break out of loop
  350.     DEC HL ;undo change to hl
  351.     LD  A, D
  352.     ADD A, 8
  353.     LD  D, A    
  354.     LD (pencol), DE;inc row by 8
  355.     b_call(_VPutS);display sbuff[n], move HL to point to next string
  356.     DJNZ _DML1  ;repeat untill B=0
  357.  
  358.  
  359.  
  360. ;;;;;;EVERYTHING FROM HERE DOWN NEEDS TO BE REDONE
  361. ;;;;;;CONSIDER REDOING THIS WITH SELF MODIFYING CODE FOR THE BIT INSTRUCTION SO THIS CAN BE LOOPED
  362. _DML2: ;;now display the stupid little options at the bottom of the screen
  363.     LD E, 0 ;load a 2 chars up
  364.     LD D, 63-14
  365.     LD B, 19 ;19 iterations required to cover the whole screen
  366.     LD (pencol), DE
  367.     LD A, $5f  ;a= '_'
  368. _DML3: ;loop and display "_____" across the bottom of the screen
  369.     b_call(_PutC)
  370.     DJNZ _DML3
  371.  
  372.     ;;now we need to insert the code to actually draw the dumb little text things based off of the flags in b,
  373.     POP BC
  374.  
  375.  
  376.     ;;code to FIGURE OUT WHICH BUTTON SEST
  377.     ;we want to make B= COUNTER, C= FLAGS
  378. ;because there are two padding buttons being inserted, we need to shift two bits of C over two spaces
  379. ;old C %0000FFFF new C %00ff00ff where f = flag bit
  380.     LD  A,B ;four buttons, two pads
  381.     LD  B,C
  382.     Ld  C,A ;
  383.     SLA C
  384.     SLA C
  385.     AND C ;;do A & C, then mask off middle bits
  386.     AND %00110011
  387.     LD  HL, bs00;hl =first button
  388.     LD D,63-7
  389.     LD E, 0
  390.  
  391.  
  392. _DMButL0: ;check and do first button   
  393. ;hl points to next string to display
  394.     LD (pencol), DE  ;update pencol regardless of button being enabled,
  395.     SRL C ;check flags[n]
  396.     JP NC, _DMNoBut
  397.     b_call(_VPutS) ;display First String and happyness
  398.     JR _DMButL1
  399. _DMNoBut:
  400.     INC HL
  401.     INC HL
  402.     INC HL
  403.     INC HL
  404.     INC HL ;;add 5 hl
  405. _DMButL1:
  406.     LD  A, E
  407.     ADD A, 17
  408.     LD  E, A
  409.     LD (pencol), DE  ;update pencol regardless of button being enabled,
  410.     DJNZ _DMButL0   ;loop to display the rest of the buttons if B still has shit
  411.  
  412. DML4: ;;we are done displaying the stupid menu things
  413. .db "done with menu",0
  414.     push hl
  415.     ld hl, dml4
  416.     call print_wait
  417.     pop hl
  418.     RET ;;give control back to the calling function
  419.  
  420.  
  421.  
  422. ;=============================================================================================================================================    
  423. ;ERROR CONDITIONS ================================================================================================================================
  424. ;=============================================================================================================================================
  425. ;the race file was not found
  426. ;bitch and quit
  427. raceNotFound:  
  428.     LD HL, raceFileNotFoundStr
  429.     call print_wait
  430.     jr  quit
  431.  
  432. raceCorrupt:
  433.     LD HL, raceCorruptStr
  434.     call print_wait
  435.     jr  quit
  436.  
  437.  
  438. ;first item on stack is name of string we tried to look up
  439. ;function copies error message to longs1, points DE to name of not_found file, concatinates them, bitches, then quits
  440. genTabNotFound:  
  441.     LD HL, fileNotFoundStr
  442.     CALL stringLength     ;preserves HL
  443.     LD  B, 0
  444.     LD  C, A    ;bc = lenght of base error string
  445.     LD  DE, longs1  
  446.     ldir        ;Copy race_corrupt string into Longs1
  447.     LD  HL, longs1
  448.     POP DE      ;DE = name of not found file
  449.     CALL concat ;combine them, HL = address of longs1
  450.     Xor A       ;A=0
  451.     LD   (DE), A;make sure end of string is null
  452.     CALL print_wait;bitch our errormessage
  453.     jp quit  ;quit
  454.  
  455.  
  456.  
  457. ;;similar idea to the genTabNotFound function
  458. ;;the table was found, but something is wrong with it
  459. ;;create an error message and display it
  460. genTableCorrupt:
  461.     LD HL, fileCorruptStr
  462.     CALL stringLength     ;preserves HL
  463.     LD  B, 0
  464.     LD  C, A    ;bc = lenght of base error string
  465.     LD  DE, longs1  
  466.     ldir        ;Copy race_corrupt string into Longs1
  467.     LD  HL, longs1
  468.     POP DE      ;DE = name of not found file
  469.     CALL concat ;combine them, HL = address of longs1, DE= end
  470.     XoR A
  471.     LD   (DE), A;make sure end of string is null
  472.     CALL print_wait;bitch our errormessage
  473.     jp quit  ;quit
  474.  
  475.  
  476.     ;make a str.lenght function that takes HL as str* and returns HL= first char of string, A = string's length
  477.  
  478. ;=============================================================================================================================================    
  479. ;CLEAR SBUFF================================================================================================================================
  480. ;=============================================================================================================================================
  481. ;clears sbuff or s1buff
  482. ;INPUT: DE =address of sbuff0 or s1buff0   
  483. ;
  484. ;
  485. clearsbuff:
  486. .db "clearsbuff",0
  487.     push HL
  488.     LD HL, clearsbuff
  489.     call print_wait
  490.     pop hl
  491.     LD B,90 ;90 bytes to clear
  492.     LD A,0
  493. clearsbuff1:   
  494.     LD (DE),A
  495.     INC DE
  496.     DJNZ clearsbuff1
  497.     ret
  498.  
  499. ;=============================================================================================================================================    
  500. ;LEAVE PROGRAM================================================================================================================================
  501. ;=============================================================================================================================================
  502.  
  503. quit:
  504.     LD  HL, quitstr
  505.     call println
  506.     ;LD  HL, (stackpointer)
  507.     ;LD  E, (HL)
  508.     ;INC HL
  509.     ;LD  D, (HL)
  510.     ;EX  DE, HL ;not sure if this is needed, but i just want it to work *sob*
  511.     LD  SP, (stackpointer)
  512.     LD  HL, (stackpointer)
  513.     b_call(_DispHL)
  514.     EI
  515.     RET        ;return control to the operating system
  516.  
  517. ;=============================================================================================================================================    
  518. ;Compare HL to End of Index================================================================================================================================
  519. ;=============================================================================================================================================
  520. ;;Make sure HL hasn't left the index segment of the Race or Special Ability file
  521. ;;IN: HL- Current location in index (address)
  522. ;;    DE- Pointer to start of TABLE SECTION
  523. ;;
  524. ;;out:CF- reset if we are out of bounds, set if we are good
  525. ;;
  526. ;;Function: HL>=DE (NC if true, C if false)  We have a problem if  HL is bigger
  527. ;;DESTROYS: A
  528. cpHL_DE:
  529. ;.db "cpHL_de",0
  530. ;   push hl
  531. ;   ld hl, cpHL_DE
  532. ;   call print_wait
  533. ;   pop hl
  534.     LD  A, H  ;a= msb of CURRENT index
  535.     CP  D
  536.     JP  z, cph_lsb;if the MSBs are equal, compare the LSBs, else, return result of comparison
  537.     RET       ;the comparison was resolved, return the carry flag result
  538. cph_lsb:
  539.     LD  A, L  ;a= lsb of TABLE_POINTER
  540.     CP  E
  541.     RET       ;return NC if HL
  542.  
  543. ;=============================================================================================================================================    
  544. ;(HL) NULL?================================================================================================================================
  545. ;=============================================================================================================================================
  546.  
  547. ;;OUT: CF status, HL+=1
  548. ;;DESTROYS: A
  549. cpHL_0:
  550.     LD  A, (HL)  ;a= msb of CURRENT index
  551.     CP  0
  552.     JP  z, cph0_lsb;if the MSBs are equal, compare the LSBs, else, return result of comparison
  553.     RET NZ        ;the comparison was resolved, return the carry flag result
  554. cph0_lsb:
  555.     INC HL
  556.     LD  A, (HL)  ;a= lsb of old (HL)
  557.     CP  0
  558.     RET       ;return NC if HL 
  559.  
  560. ;=============================================================================================================================================    
  561. ;FIND STRING LENGTH================================================================================================================================
  562. ;=============================================================================================================================================
  563. ;INPUT: HL -address of string
  564. ;OUTPUT:HL -address of string
  565. ;       A  -length of string including the null
  566. ;
  567. stringLength:
  568.     PUSH HL
  569.     PUSH BC       ;Save BC
  570.     LD A, 0      
  571.     LD C, 0       ;gonna start at zero because BC will decriment with each iteration, finding (neg)C will tell us the length of the string
  572.     LD B, 0
  573.     CPIR          ;search for the null at the end of the string (compare (HL) to A) , where A is zero
  574.     LD A, C       ;a= negative length of string
  575.     NEG           ;a= length of string
  576.     POP BC
  577.     POP HL
  578.     ret          
  579.  
  580.  
  581. testLength:
  582.     LD HL, testStr
  583.     call stringLength
  584.     LD H, 0
  585.     LD L, A
  586.     call printHL_wait
  587.     ret    
  588. ;=============================================================================================================================================    
  589. ;Concatinate Strings================================================================================================================================
  590. ;=============================================================================================================================================
  591. ;INPUT: HL -address of string1
  592. ;       DE -Address of string2
  593. ;OUTPUT:HL -address of string1
  594. ;       DE -end of string1
  595. ;Calculates String1+String2, assuming String1 has enough space after it to house String2
  596.  
  597. concat:
  598.     PUSH BC
  599.     PUSH HL
  600.     CALL stringLength  ;get length of string1
  601.     LD  B, 0
  602.     LD  C, A  ;BC =string1.length()
  603.     ADD HL, BC;HL points to end of string
  604.     DEC L     ;compensate for the null, now HL points to the null
  605.     EX  DE, HL; DE is now Str1, HL, str2
  606.     CALL StringLength
  607.     LD  C,A   ;BC =string2.length()
  608.     LDIR      ;copy bytes from string2 to string1
  609.     xor A
  610.     LD (DE), A ;add a zero to the end of the string
  611.     POP HL
  612.     POP BC
  613.     RET
  614.  
  615.  
  616. testConcat:
  617.     LD HL, dbg4
  618.     LD DE, dbg1
  619.     call concat
  620.     call print_wait ;display the concatinated string
  621.     ret
  622.  
  623.  
  624.  
  625. ;=============================================================================================================================================    
  626. ;DIVIDE HL by D================================================================================================================================
  627. ;=============================================================================================================================================
  628. ;input HL, D
  629. ;output HL, A
  630.  
  631. Div_HL_D:            ; HL = HL ÷ D, A = remainder
  632.     XOR    A         ; Clear upper eight bits of AHL
  633.     LD     B, 16      ; Sixteen bits in dividend
  634. _loop:
  635.     ADD    HL, HL     ; Do a SLA HL
  636.     RLA              ; This moves the upper bits of the dividend into A
  637.     JR     C, _overflow
  638.     CP     D         ; Check if we can subtract the divisor
  639.     JR     C, _skip   ; Carry means D > A
  640. _overflow:
  641.     SUB    D         ; Do subtraction for real this time
  642.     INC    L         ; Set bit 0 of quotient
  643. _skip:
  644.     DJNZ   _loop
  645.     RET
  646.  
  647.  
  648. ;=============================================================================================================================================    
  649. ;PRINT TEXT-----takes HL  as an arg================================================================================================================================
  650. ;=============================================================================================================================================
  651. println:
  652.     PUSH HL
  653.     PUSH DE
  654.     PUSH BC
  655.     PUSH AF
  656.     b_call(_ClrLCDFull)
  657.     POP  AF
  658.     POP  BC
  659.     POP  DE
  660.     LD  L, 0        ;col
  661.     LD  H, 10       ;row
  662.     LD (pencol), HL
  663.     POP HL          ;HL was never POPed before, hl now ready to display
  664.     b_call(_VPutS)  ;print the message
  665.     ret             ;go back
  666.  
  667.  
  668.  
  669. ;=============================================================================================================================================    
  670. ;PRINT TEXT AT POSITION ----takes HL && BC as an arg================================================================================================================================
  671. ;=============================================================================================================================================
  672. println2:
  673.     PUSH DE
  674.     PUSH HL
  675.     PUSH BC
  676.     PUSH AF
  677.     b_call(_ClrLCDFull)
  678.     POP  AF
  679.     POP  BC
  680.     POP  HL
  681.     POP  DE
  682.     LD (pencol), BC
  683.     b_call(_VPutS)  ;print the message
  684.     ret             ;go back
  685.  
  686.  
  687. ;=============================================================================================================================================    
  688. ;wait=========================================================================================================================================
  689. ;=============================================================================================================================================
  690. wait:
  691.     ret  ;DOESNT WORK, JUST EXITS
  692.     PUSH HL
  693.     LD  HL, $FF
  694. wl1:
  695.     DEC HL
  696.     JP nz, wl1 
  697.     POP HL
  698.     ret             ;go back
  699.  
  700.  
  701. ;=============================================================================================================================================    
  702. ;PRINT AND WAIT=========================================================================================================================================
  703. ;=============================================================================================================================================
  704. ;clears screen, prints string, waits for button press, used mainly for debugging and displaying program status
  705. ;HL - adress of string to print
  706. ;SAVES all registers
  707. print_wait:
  708.     PUSH BC
  709.     LD B,0
  710.     LD C,0
  711.     call println2
  712.     PUSH AF
  713.     PUSH HL
  714.     PUSH DE
  715.     b_call(_GetKey)
  716.     ;call wait
  717.     POP  DE
  718.     POP  HL
  719.     POP  AF
  720.     POP  BC
  721.     ret
  722.  
  723.  
  724.  
  725. ;=============================================================================================================================================    
  726. ;PRINT HL AND WAIT=========================================================================================================================================
  727. ;=============================================================================================================================================
  728. ;clears screen, prints string, waits for button press, used mainly for debugging and displaying program status
  729. ;HL - adress of string to print
  730. ;SAVES all registers
  731. printHL_wait:
  732.     PUSH BC
  733.     PUSH AF
  734.     PUSH HL
  735.     PUSH DE
  736.     b_call(_DispHL)
  737.     b_call(_GetKey)
  738.     POP  DE
  739.     POP  HL
  740.     POP  AF
  741.     POP  BC
  742.     ret
  743. ;  
  744.  
  745.  
  746.  
  747.  
  748.  
  749.  
  750. ;=================file specific data segment=========================
  751. racefilename:    .db $15, "Races",0 ;appvar tok and name
  752. racefile:        .dw 0,0            ;address in RAM of racefile LITTLE ENDIAN
  753. racefileSize:    .dw 0,0            ;size of said file  LITTLE ENDIAN
  754. raceTableOffset: .dw 0,0            ;offset of actual races from index LITTLE ENDIAN
  755. raceTablePointer:.dw 0,0            ;pointer to first byte of raceTable, LITTLE ENDIAN
  756.  
  757.  
  758. m0index: .db 0  ;;we can have up to 3 nested menus with saved indexes before something has to go
  759. m1index: .db 0
  760. m2index: .db 0
  761.  
  762. sizeStrTabName:  .db $15, "sizeStr",0 ;for the general string tables
  763. sizeStrTab:      .dw 0,0           
  764.  
  765. classStrTabName: .db $15, "classStr",0
  766. classStrTab:     .dw 0,0           
  767.  
  768. sword:.db 0  ;just a place to store swap data
  769.  
  770. it:.db 0  ;for counting iterations of a loop
  771.  
  772.  
  773. ;;read only from here down
  774. testStr: .db "0123456789",0 ;10 bytes + null
  775. raceCorruptStr:  .db "Race file corrupt",0
  776. raceFileNotFoundStr: .db "Race file not found",0
  777. fileNotFoundStr:  .db "File Not Found:" ,0 ;15 bytes +null
  778. fileCorruptStr:   .db "File Corrupt:",0    ;13 bytes +null
  779. ;button strings
  780. bs00: .db "back",0
  781. bs01: .db "info",0
  782. .db 0,0,0,0,0,0,0,0,0,0 ;10 bytes padding for future buttons
  783. bs02: .db "up  ",0
  784. bs03: .db "down",0
  785.  
  786. ;menuIdex: .db 0;general data for current menu index. must be saved to stack when nested menu's created
  787.  
  788. ;==========================DATA SEGMENT==============================
  789. newCharStr: .db "Make a new Character",0
  790. enterNamestr: .db "Enter a name",0
  791. ;;debug strings------------------------------------------------
  792. outOfMemStr: .db "no memory exists",0
  793. probWithName: .db "Prob With Name",0
  794. quitstr: .db "ending",0
  795. charmade: .db "Character made!",0
  796. dbg1: .db "Check 1",0,
  797. dbg2: .db "Check 2",0,
  798. dbg3: .db "Check 3",0,
  799. dbg4: .db "Check 4",0,
  800.  
  801.  
  802.  
  803. ;;begin blank var segment
  804.  
  805. ;two short contiguous string buffers
  806. sbuff0:  .db $FF,0,0,0,0,0,0,0,0 ;8 char buffer, 9 bytes long
  807. sbuff1:  .db $FF,0,0,0,0,0,0,0,0 ;8 char buffer, 9 bytes long
  808. sbuff2:  .db $FF,0,0,0,0,0,0,0,0 ;8 char buffer, 9 bytes long
  809. sbuff3:  .db $FF,0,0,0,0,0,0,0,0 ;8 char buffer, 9 bytes long
  810. sbuff4:  .db $FF,0,0,0,0,0,0,0,0 ;8 char buffer, 9 bytes long
  811. sbuff5:  .db $FF,0,0,0,0,0,0,0,0 ;8 char buffer, 9 bytes long
  812. sbuff6:  .db $FF,0,0,0,0,0,0,0,0 ;8 char buffer, 9 bytes long
  813. sbuff7:  .db $FF,0,0,0,0,0,0,0,0 ;8 char buffer, 9 bytes long
  814. sbuff8:  .db $FF,0,0,0,0,0,0,0,0 ;8 char buffer, 9 bytes long
  815. sbuff9:  .db $FF,0,0,0,0,0,0,0,0 ;8 char buffer, 9 bytes long
  816.  
  817. s2buff0: .db $FF,0,0,0,0,0,0,0,0 ;8 char buffer, 9 bytes long
  818. s2buff1: .db $FF,0,0,0,0,0,0,0,0 ;8 char buffer, 9 bytes long
  819. s2buff2: .db $FF,0,0,0,0,0,0,0,0 ;8 char buffer, 9 bytes long
  820. s2buff3: .db $FF,0,0,0,0,0,0,0,0 ;8 char buffer, 9 bytes long
  821. s2buff4: .db $FF,0,0,0,0,0,0,0,0 ;8 char buffer, 9 bytes long
  822. s2buff5: .db $FF,0,0,0,0,0,0,0,0 ;8 char buffer, 9 bytes long
  823. s2buff6: .db $FF,0,0,0,0,0,0,0,0 ;8 char buffer, 9 bytes long
  824. s2buff7: .db $FF,0,0,0,0,0,0,0,0 ;8 char buffer, 9 bytes long
  825. s2buff8: .db $FF,0,0,0,0,0,0,0,0 ;8 char buffer, 9 bytes long
  826. s2buff9: .db $FF,0,0,0,0,0,0,0,0 ;8 char buffer, 9 bytes long
  827.  
  828.  
  829.  
  830. ;two more general purpose 8 char +null strings
  831. string1:    .db 0,0,0,0,0,0,0,0,0 ;8 bytes and null
  832. appvartok:  .db $15               ;point HL to here when making an appvar name to include  the token
  833. string2:    .db 0,0,0,0,0,0,0,0,0 ;8 bytes and null
  834.  
  835. longs1: .db "000000000000000000000000000000",0 ;30 char string + null (31 bytes)
  836. longs2: .db "000000000000000000000000000000",0 ;30 char string + null (31 bytes)
  837.  
  838. meds1:  .db "000000000000000",0 ;15 byte string+null
  839. meds2:  .db "000000000000000",0 ;15 byte string+null
  840.  
  841.  
  842. curFile: .db 0
  843. openFiles .dw 00, 00, 00   
  844.  
  845. .end
  846. .end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement