home *** CD-ROM | disk | FTP | other *** search
/ ticalc.org / ticalc_org_rev_b.iso / archives / 86 / asm / source / orzcon86.asm < prev    next >
Encoding:
Assembly Source File  |  2001-07-01  |  11.6 KB  |  397 lines

  1. ;OrzEd-IC now uses the consolidated ACZ includes available with AsmStudio 3.1 or from the ACZ
  2. ; homepage at http://acz.calc.org/
  3. #include "ram86.h"
  4. #include "rom86.h"
  5. #include "asm86.h"
  6.  
  7. #define lTable1 progEnd
  8. #define lTable2 progEnd + $20
  9. #define lTable3 progEnd + $40
  10.  
  11. curLevelChar        =    $E748
  12. curLevel            =    $E749
  13. curOffset           =    $E74B
  14.  
  15. .org _asm_exec_ram
  16.  nop                     ;Mark program as AShell 1.1 compatable.
  17.  jp AsmStart             ;Jump to program init routine.
  18.  .dw 0                   ;Table version 0.
  19.  .dw strDesc             ;Pointer to description string.
  20.  
  21. goThree:
  22.  ld a, '3'               ;For display.
  23.  ld de, $0040            ;Get the address of the third level.
  24.  jr goNum
  25. goTwo:
  26.  ld a, '2'               ;For display.
  27.  ld de, $0020            ;Get the address of the second level.
  28.  jr goNum
  29. goOne:
  30.  ld a, '1'               ;For display.
  31.  ld de, $0000            ;Get the address of the first level.
  32. goNum:
  33.  ld (curLevelChar), a    ;This is read to get level display character.
  34.  ld (curLevel), de       ;Write it to the current level address.
  35.  jr preMain              ;Redisplay screen before continuing.
  36.  
  37. lL_NoProg:
  38.  ld de, strNoProg
  39.  jp dispMsg
  40. lL_NotValid:
  41.  ld de, strNotValid
  42.  jp dispMsg
  43.  
  44. AsmStart:
  45.  call _runindicoff
  46. nL_Restart:
  47.  call _clrScrn
  48.  ld a, '1'               ;This is just the easiest way of keeping track of
  49.  ld (curLevelChar), a    ; the current level number.
  50.  
  51. loadLevel:
  52.  call nameLevel          ;Get name to load from.
  53.  ld hl, strName          ;Put level set title into _OP1
  54.  rst 20h
  55.  ld a, (intNameLen)
  56.  ld (_OP1 + 1), a
  57.  rst 10h                 ;Gets var info if it exists.
  58.  jr c, lL_NoProg         ;If it doesn't, generate an error.
  59.  and $1F                 ;Mask out flags
  60.  cp $12                  ;Is it a program?
  61.  jr nz, lL_NotValid      ;If not, generate an error.
  62.  ld a, b                 ;move bde -> ahl
  63.  ex de, hl
  64.  call _load_ram_ahl      ;Load appropriate RAM page.
  65.  ld c, (hl)
  66.  inc hl
  67.  ld b, (hl)
  68. lL_Find:
  69.  ld a, $D0
  70.  cpir
  71.  xor a
  72.  cp b
  73.  jr nz, lL_Check
  74.  cp c
  75.  jr z, lL_NotValid      ;If the signature doesn't exist, generate an error.
  76. lL_Check:
  77.  ld a, $4F
  78.  cp (hl)
  79.  jr nz, lL_Find
  80.  inc hl
  81.  ld (curOffset), hl
  82. preMain:
  83.  call reDispScreen       ;Redraws the entire display.
  84. main:
  85.  call _get_key
  86.  dec a                   ;Move down 2 lines.
  87.  jr z, mDown
  88.  dec a                   ;Move left 4 bricks.
  89.  jr z, mLeft
  90.  dec a                   ;Move right 4 bricks.
  91.  jr z, mRight
  92.  dec a                   ;Move up 2 lines.
  93.  jr z, mUp
  94.  cp K_3 - 4              ;Load the third level.
  95.  jr z, goThree
  96.  cp K_2 - 4              ;Load the second level.
  97.  jr z, goTwo
  98.  cp K_1 - 4              ;Load the first level.
  99.  jr z, goOne
  100.  cp K_F1 - 4             ;Clear all levels and reset name.
  101.  jp z, saveLevel
  102.  cp K_F5 - 4             ;If F5 was pressed, just exit.
  103.  jr nz, main
  104. doExit:
  105.  ld a, $E1               ;Used to clear shiftflags 3-6.
  106.  and (iy+shiftflags)
  107.  ld (iy + shiftflags), a
  108.  jp _clrScrn             ;Clear screen before returning to shell.
  109.  
  110. mDown:
  111.  ld hl, (curOffset)
  112.  ld de, $0008
  113.  add hl, de
  114.  ld (curOffset), hl
  115.  jr preMain
  116.  
  117. mLeft:
  118.  ld hl, (curOffset)
  119.  dec hl
  120.  ld (curOffset), hl
  121.  jr preMain
  122.  
  123. mRight:
  124.  ld hl, (curOffset)
  125.  inc hl
  126.  ld (curOffset), hl
  127.  jr preMain
  128.  
  129. mUp:
  130.  ld hl, (curOffset)
  131.  ld de, -$0008
  132.  add hl, de
  133.  ld (curOffset), hl
  134.  jr preMain
  135.  
  136. reDispScreen:
  137.  push ix
  138.  ld ix, 0                ;Start at the first brick.
  139.  ld de, (curLevel)       ;Load the memory offset of the current level.
  140.  ld hl, (curOffset)
  141.  add hl, de
  142.  ex de, hl
  143.  ld b, $20               ;We need to process 32 bytes.
  144. rDS_byte:
  145.  push bc                 ;Save the byte count.
  146.  ld b, 4                 ;Four blocks per byte.
  147.  ld a, (de)              ;Get the current byte.
  148.  ld c, a
  149. rDS_block:
  150.  rlc c                   ;Bits 7 and 6 to 1 and 0.
  151.  rlc c
  152.  ld a, c
  153.  and $03                 ;Ignore bits 2-7.
  154.  push de                 ;Can't lose this!
  155.  call drawBlock          ;Draw whatever type of block bits 1 and 0 represent.
  156.  pop de                  ;Restore data pointer.
  157.  inc ixl                 ;Increment the column.
  158.  ld a, $10               ;If we hit the end of a line, 
  159.  cp ixl
  160.  jr nz, rDS_goBlock
  161.  ld ixl, 0
  162.  inc ixh                 ;Increment the row.
  163. rDS_goBlock:
  164.  djnz rDS_block          ;If we're not done with this byte, loop.
  165.  inc de                  ;Next byte!
  166.  pop bc                  ;Restore the byte count.
  167.  djnz rDS_byte           ;If we're not done with the level, loop.
  168.  ld hl, $0004            ;Just below the level display.
  169.  ld (_curRow), hl
  170.  ld a, (curLevelChar)    ;Get level number (stored as a char)
  171.  call _putc
  172.  ld hl, strName          ;Current name of the level set.
  173.  call _puts
  174.  ld hl, $3906            ;Set up menu at bottom of screen.
  175.  ld (_penCol), hl
  176.  ld hl, strSave
  177.  call _vputs
  178.  ld hl, $396C
  179.  ld (_penCol), hl
  180.  ld hl, strExit
  181.  call _vputs
  182.  pop ix                  ;Restore cursor position.
  183.  ret
  184.  
  185. saveLevel:
  186.  ld hl, (curOffset)
  187.  ld de, lTable1
  188.  ld bc, $60
  189.  ldir
  190.  ld hl, strName          ;Copy name w/o leading length into _OP1.
  191.  rst 20h
  192.  ld a, (intNameLen)      ;Retrieve name length.
  193.  ld (_OP1 + 1), a        ;Add leading length byte (z80 is byte-reversed).
  194.  rst 10h                 ;Check to see if it already exists.
  195.  call _delvar            ;If it does, generate an error.
  196.  ld hl, $70              ;$60 data + $0E code + 2 asm header = $70.
  197.  call _createprog        ;Allocate program memory and create VAT entry.
  198.  ld a, b                 ;Move bde -> ahl.
  199.  ex de, hl
  200.  call _load_ram_ahl      ;Set RAM page and convert hl to ASIC.
  201.  ld de, rawProg          ;Copy program contents from _asm_exec_ram to
  202.  ld bc, $70              ; the memory just allocated by _CREATEPROG.
  203.  ex de, hl
  204.  inc de                  ;Skip the size bytes.
  205.  inc de
  206.  ldir
  207.  ld de, strGoodSave
  208. dispMsg:
  209.  ld hl, $0005            ;Display below name.
  210.  ld (_curRow), hl
  211.  ex de, hl               ;The offset of the text to display must be in de.
  212.  call _puts              ;Messages must be null-terminated.
  213.  call _pause             ;Hang around until they press a key.
  214.  ld hl, $FE80            ;$FE80 = video address of the sixth line.
  215.  ld de, $FE81
  216.  ld bc, $017F
  217.  ld (hl), 0
  218.  ldir
  219.  jp doExit
  220.  
  221. nameLevel:
  222.  ld a, (iy + shiftflags) ;Get shiftflags.
  223.  or $50                  ;Set shiftAlpha and shiftALock.
  224.  ld (iy + shiftflags), a ;Save shiftslags.
  225.  call _cursorOn          ;We want the cursor displayed during text entry.
  226.  ld de, strName + 2      ;Where the characters will go.
  227.  ld a, (intNameLen)      ;But first, we need to add the current offset.
  228.  ld l, a
  229.  ld h, 0
  230.  add hl, de
  231.  push hl                 ;I think _getkey screws with de and hl...
  232. nL_Loop:                 ;Used to update the display.
  233.  ld hl, $0304            ;First letter of the name display.
  234.  ld (_curRow), hl
  235.  ld a, $20
  236.  ld b, 9
  237. nL_OverWrite:
  238.  call _putc
  239.  djnz nL_OverWrite
  240.  ld hl, $0304            ;First letter of the name display.
  241.  ld (_curRow), hl
  242.  ld hl, strName + 2      ;(Re)display the current name.
  243.  call _puts
  244. nL_GetKey:
  245.  call _getkey            ;Use _getkey so we get Alpha handled for us.
  246.  cp kEnter               ;If it's enter, try to use this filename.
  247.  jr z, nL_Next
  248.  cp kDel                 ;If it's delete, remove the last charater typed.
  249.  jr z, nL_Back
  250.  add a, $14              ;L0 (font code) - k0 (key code) = 14 hex.
  251.  cp L0                   ;If it's less than 0, it's a bad character.
  252.  jr c, nL_GetKey
  253.  cp L9 + 1               ;If it's not more than 9, it's a numeral.
  254.  jr c, nL_PrePutKey
  255.  add a, $5               ;LcapA - kCapA = $14 + $5
  256.  cp LcapA                ;If it's less that A, it's a bad character.
  257.  jr c, nL_GetKey
  258.  cp LcapZ + 1            ;If it's not more than Z, it's a capital letter.
  259.  jr c, nL_PutKey
  260.  add a, $6               ;Lz - kz = $14 + $5 + $6
  261.  cp Lz + 1               ;If it's not more than z, it's a lower-case letter.
  262.  jr nc, nL_GetKey        ;Otherwise, it's a bad character.
  263.  jr nL_PutKey
  264. nL_PrePutKey:            ;Need to make sure this isn't the first character.
  265.  ld c, a                 ;We'll need a.
  266.  ld a, (intNameLen)      ;Grab the name length.
  267.  ld b, 0                 ;The first character cannot be a number.
  268.  cp b
  269.  jr z, nL_GetKey         ;Numbers can't be the first character of a filename.
  270.  ld a, c
  271. nL_PutKey:
  272.  ld c, a                 ;We'll need a.
  273.  ld a, (intNameLen)      ;Grab the name length.
  274.  ld b, 8                 ;Filenames can't exceed 8 characters.
  275.  cp b
  276.  jr z, nL_GetKey
  277.  inc a                   ;Increase the character count.
  278.  ld (intNameLen), a      ;Store the name length.
  279.  pop hl                  ;Retrieve memory counter.
  280.  ld (hl), c              ;Load the character into memory.
  281.  inc hl                  ;Increment the memory counter.
  282.  push hl                 ;Store memory counter.
  283.  jr nL_Loop              ;Redisplay.
  284. nL_Back:
  285.  ld a, (intNameLen)      ;Grab the name length.
  286.  ld b, 0                 ;Can't backspace if it's there aren't any characters!
  287.  cp b
  288.  jr z, nL_GetKey
  289.  dec a                   ;Decrease the character count.
  290.  ld (intNameLen), a      ;Store the name length.
  291.  pop hl
  292.  dec hl                  ;Decrement the memory counter.
  293.  ld (hl), b              ;Zero out the last character.
  294.  push hl
  295.  jr nL_Loop              ;Redisplay
  296. nL_Next:
  297.  ld a, (intNameLen)      ;Grab the name length.
  298.  ld b, 0                 ;Can't use a zero-length name.
  299.  cp b
  300.  jr z, nL_GetKey
  301.  call _cursorOff         ;Get rid of cursor.
  302.  pop hl
  303.  ld (intNameLen), a      ;Store the name length.
  304.  ret
  305.  
  306. drawBlock:
  307.  call getOffset          ;Change hl into screen offset.
  308.  ld de, $0010            ;One full line on the screen.
  309.  or a                    ;Is a 0?
  310.  jr z, drawClear         ;If so, clear the block.
  311.  ld (hl), %11111111      ;All others start with $FF
  312.  add hl, de
  313.  dec a                   ;Was a 1?
  314.  jr z, drawNorm          ;If so, draw a normal block.
  315.  dec a                   ;Was a 2?
  316.  jr z, drawTough         ;If so, draw a tough block.
  317.  ld a, %11111111         ;Else, it's solid.
  318.  ld (hl), a
  319.  add hl, de              ;Move down one line.
  320.  ld (hl), a
  321.  add hl, de
  322.  ld (hl), a
  323.  ret
  324. drawTough:
  325.  ld (hl), %11000011      ;Second line of sprite.
  326.  add hl, de
  327.  ld (hl), %11000011      ;Third line of sprite.
  328.  add hl, de
  329.  ld (hl), %11111111      ;Last line of sprite.
  330.  ret
  331. drawNorm:
  332.  ld (hl), %10000001
  333.  add hl, de
  334.  ld (hl), %10000001
  335.  add hl, de
  336.  ld (hl), %11111111
  337.  ret
  338. drawClear:
  339.  ld (hl), a              ;a is already 0.
  340.  add hl, de
  341.  ld (hl), a
  342.  add hl, de
  343.  ld (hl), a
  344.  add hl, de
  345.  ld (hl), a
  346.  ret
  347.  
  348. getOffset:
  349.  push ix                 ;Copy ix into de.
  350.  pop de
  351.  ld l, d                 ;Change ixh into a 16-bit value in hl.
  352.  ld h, 0
  353.  ld d, $FC               ;Load d with the upper byte of the screen offset.
  354.  add hl, hl              ;hl = Row * 64
  355.  add hl, hl
  356.  add hl, hl
  357.  add hl, hl
  358.  add hl, hl
  359.  add hl, hl
  360.  add hl, de              ;hl = Screen Offset + Row * 64 + Column
  361.  ret
  362.  
  363. dataArea:
  364. strDesc:
  365.  .db "Orzunoid Level Converter v.5b", 0
  366. strGoodSave:
  367.  .db "Level set saved.", 0
  368. strName:
  369.  .db ": Untitled", 0
  370. intNameLen:
  371.  .db 8
  372. strNoProg:
  373.  .db "No such file exists!", 0
  374. strNotValid:
  375.  .db "Not a level set!", 0
  376. strNew:
  377.  .db "New", 0
  378. strLoad:
  379.  .db "Load", 0
  380. strSave:
  381.  .db "Save", 0
  382. strTest:
  383.  .db "Test", 0
  384. strExit:
  385.  .db "Exit", 0
  386. rawProg:
  387.  .db $8E, $28            ;Assembly program ID bytes (TI)
  388.  ld de, $C012            ;Level storage in RAM.
  389.  ld hl, $D754            ;_asm_exec_ram + $0C
  390.  ld bc, $0062            ;# of bytes to copy (3 levels * $20 + 2)
  391.  ldir
  392.  ret
  393.  .db $D0, $4F            ;These tell Orzunoid that this is a valid level set.
  394.  
  395. progEnd:
  396. .end
  397.