home *** CD-ROM | disk | FTP | other *** search
- .NOLIST
- #define equ .equ
- #define EQU .equ
- #define end .end
- #include "ti83asm.inc"
- #include "tokens.inc"
- .LIST
-
- #define temp 8265h ; temporary
- #define levelname 8266h ; name of current level
- #define level 826Ah ; pointer to symbol table entry of current level
- #define row 826Ch ; level offset row
- #define col 826Eh ; level offset col
- #define itemnum 826Fh ; current item (while editing)
-
- _createprog .equ 448Ah ; create new program (name in op1)
- _memfree .equ 441Ah ; free memory into hl
- lcddata .equ 11h ; lcd data port
-
- progobj .equ 05h ; program
- protprogobj .equ 06h ; protected program
- listobj .equ 01h ; list
- clistobj .equ 0Dh ; complex list
-
- .org 9327h
-
- call _runindicoff
-
- ; main screen select your option: new or edit
- ;
- ; up - changes selection
- ; down - changes selection
- ; 2nd - selects
- ; clear - quits program
-
- titlescreen:
-
- call _grbufclr ; clear buffer
- ld hl,title ; draw title
- ld de,plotsscreen+60 ;
- ld bc,300 ;
- ldir ;
- set textwrite,(iy+sgrflags) ; write to buffer
- ld hl,$221D ; write "Level Editor"
- ld (pencol),hl ;
- ld hl,editor ;
- call _vputs ;
- ld hl,$2D2A ; write "New"
- ld (pencol),hl ;
- ld hl,newstr ;
- call _vputs ;
- ld hl,$342A ; write "Edit"
- ld (pencol),hl ;
- ld hl,editstr ;
- call _vputs ;
- res textwrite,(iy+sgrflags) ; write to display
- ld hl,plotsscreen+544 ; invert menu item
- call invert_area ;
- call bufcpy ; copy buffer to screen
- ld a,0 ; temp holds selected menu item
- ld (temp),a ;
-
- title_loop:
-
- call _getk
- ld a,21 ; was 2nd pressed
- call _setxxop1 ;
- call _cpop1op2 ;
- jp z,start ; make a new level
- ld a,25 ; was up pressed
- call _setxxop1 ;
- call _cpop1op2 ;
- call z,change ; make a new level
- ld a,34 ; was down pressed
- call _setxxop1 ;
- call _cpop1op2 ;
- call z,change ; select a level to edit
- ld a,45 ; was Clear pressed
- call _setxxop1 ;
- call _cpop1op2 ;
- ret z ; quit
- jr title_loop
-
- change:
-
- ld a,(temp) ; change selected menu item
- cpl ;
- ld (temp),a ;
- ld hl,plotsscreen+544 ;
- call invert_area ;
- ld hl,plotsscreen+628 ;
- call invert_area ;
- call bufcpy ;
- ret
-
- start:
-
- ld a,(temp) ; if temp is zero create new
- cp 0 ;
- jr z,new ;
- jp getlevel ; if temp is not zero edit
-
- ; screen for creating a new level
- ;
- ; 2nd - selects initial
- ; up arrow - moves initial up
- ; down arrow - moves initial down
-
- new:
-
- call clearbottom ; clear bottom of screen
- call bufcpy ; copy buffer to screen
- call _memfree ; see if there is enough mem for a new level
- ld de,1558 ;
- call _cphlde ;
- jp c,nomem ;
- ld hl,$2D21 ; write out "Name:"
- ld (pencol),hl ;
- ld hl,namestr ;
- call _vputs ;
- ld a,$36 ; position cursor
- ld (pencol),a ;
- call getinitial ; get 1st initial
- ld (levelname),a ; store initial
- ld a,$3A ; position cursor
- ld (pencol),a ;
- call getinitial ; get 2nd initial
- ld (levelname+1),a ; store initial
- ld a,$3E ; position cursor
- ld (pencol),a ;
- call getinitial ; get 3rd initial
- ld (levelname+2),a ; store initial
- ld hl,defaultprog ; copy progobj and 1st 5 chars to op1
- ld de,op1 ;
- ld bc,6 ;
- ldir ;
- ld hl,levelname ; append level name to op1
- ld bc,3 ;
- ldir ;
- call _chkfindsym ; look up new prog
- call nc,_delvar ; if it is already created delete it
- ld hl,1544 ; size 1530 bytes
- call _createprog ; create it
- ld (hl),protprogobj ; make it protected
- inc de ; skip 1st length byte
- inc de ; skip 2nd length byte
- ld bc,1544 ; length
-
- clearloop:
-
- ld a,0 ; fill level with zeros
- ld (de),a ;
- inc de ;
- dec bc ;
- ld a,b ;
- or c ;
- jr nz,clearloop ;
- dec hl
- dec hl
- dec hl
- push hl
- jp edit
-
- nomem:
-
- ld hl,$2D11 ; write "Not Enough Memory"
- ld (pencol),hl ;
- ld hl,nomemstr ;
- call _vputs ;
- call waitforkey ; wait for key press
- jp titlescreen ; return to menu
-
- ; screen for choosing an already created level to edit
- ;
- ; 2nd - selects level
- ; Alpha - changes level
-
- getlevel:
-
- ld a,0 ; temp holds the number of levels
- ld (temp),a ; if temp is 0 at the end there aren't any levels
- ld hl,(progptr) ; start of program/list symbol table
-
- level_loop:
-
- ld a,(hl) ; get object type
- and $1F ; mask off bits 0-4
- cp progobj ; is it a program?
- jr z,program ;
- cp protprogobj ; is it a protected program?
- jr z,program ;
- cp listobj ; is it a list?
- jp z,list ;
- cp clistobj ; is it a complex list?
- jp z,list ;
- ld a,(temp) ; see if count is zero
- cp 0 ;
- jr nz,getlevel ; end of program/list symbol table. start over
- call clearbottom ; clear bottom of screen
- set textwrite,(iy+sgrflags) ; write to plotsscreen
- ld hl,$2D16 ; write "There arent any"
- ld (pencol),hl ;
- ld hl,nolevel1 ;
- call _vputs ;
- ld hl,$341B ; write "levels to edit"
- ld (pencol),hl ;
- ld hl,nolevel2 ;
- call _vputs ;
- res textwrite,(iy+sgrflags) ; write to display
- call bufcpy ; copy buffer to screen
- call waitforkey ; wait for key press
- jp titlescreen ; return to title screen
-
- program:
-
- dec hl ; skip T
- dec hl ; skip DAL
- dec hl ; skip DAH
- ld b,(hl) ; get length of name
- ld a,b ;
- cp 8 ; is the name 8 chars long?
- jr z,good_prog ; if it is then it could be a valid level
-
- program_loop:
-
- dec hl ; get past name
- djnz program_loop ;
- dec hl ; next pointer
- jr level_loop ;
-
- good_prog:
-
- push hl ; save program address
- ld b,5 ; five chars to test
- ld de,defaultprog+1 ; name to test against
-
- cploop: ; compare name to base name
-
- dec hl ; next char
- ld a,(de) ;
- cp (hl) ; are they the same?
- jp nz,nextprog ; if not move on to the next program
- inc de ; next char
- djnz cploop ;
- ld de,levelname ;
- ld b,3 ;
-
- cpyloop:
-
- dec hl ; copy last 3 chars of name
- ld a,(hl) ;
- ld (de),a ;
- inc de ;
- djnz cpyloop ;
- ld a,0 ; add 0 terminator
- ld (de),a ;
- ld a,(temp) ; increment count
- inc a ;
- ld (temp),a ;
- call clearbottom ; clear bottom of screen
- set textwrite,(iy+sgrflags) ; write to plotsscreen
- ld hl,$2D23 ; write "Edit:"
- ld (pencol),hl ;
- ld hl,selectstr ;
- call _vputs ;
- ld hl,$2D33 ; write level name
- ld (pencol),hl ;
- ld hl,levelname ;
- call _vputs ;
- res textwrite,(iy+sgrflags) ; write to display
- call bufcpy
-
- key_loop:
-
- call _getk
- ld a,21 ; was 2nd pressed
- call _setxxop1 ;
- call _cpop1op2 ;
- jp z,edit ; start editing
- ld a,31 ; was Alpha pressed
- call _setxxop1 ;
- call _cpop1op2 ;
- jp z,nextprog ; next level
- jr key_loop ;
-
- nextprog:
-
- pop hl ; restore program address
- ld b,8 ; 8 chars in name
- jp program_loop ; next pointer
-
- list:
-
- dec hl ; skip T
- dec hl ; skip DAL
- dec hl ; skip DAH
- ld b,(hl) ; get length
-
- list_loop:
-
- dec hl ; skip over name
- djnz list_loop ;
- dec hl ; next pointer
- jp level_loop ;
-
- ; once you have selected or created your level you can begin editing
- ; hl should point to the program/list symbol table entry of the level
- ;
- ; 2nd - places item
- ; arrows - move item
- ; alpha - changes item
- ; clear - returns to title screen
-
- edit:
-
- pop hl ; restore address to level
- inc hl ; move to DAL
- ld d,(hl) ; copy data address to de
- inc hl ; set high score to 0
- ld e,(hl) ;
- ld hl,2 ;
- add hl,de ;
- ld (hl),0 ;
- inc hl ;
- ld (hl),0 ;
- inc hl ;
- ld (level),hl ; store address to current level data
- ld (row),hl ; current level offset
- ld a,5 ; current row offset
- ld (col),a ;
- ld a,1 ; current item number
- ld (itemnum),a ;
- call _grbufclr ; clear buffer
- call redraw ; draw out level
- call bufcpy ;
-
- edit_key_loop:
-
- call _getk
- ld a,25 ; was up pressed
- call _setxxop1 ;
- call _cpop1op2 ;
- jp z,editup ; move item up
- ld a,34 ; was down pressed
- call _setxxop1 ;
- call _cpop1op2 ;
- jp z,editdown ; move item down
- ld a,24 ; was left pressed
- call _setxxop1 ;
- call _cpop1op2 ;
- jp z,editleft ; move item right
- ld a,26 ; was right pressed
- call _setxxop1 ;
- call _cpop1op2 ;
- jp z,editright ; move item left
- ld a,21 ; was 2nd pressed
- call _setxxop1 ;
- call _cpop1op2 ;
- jp z,putitem ; put item at current position
- ld a,31 ; was Alpha pressed
- call _setxxop1 ;
- call _cpop1op2 ;
- jp z,changeitem ; toggle item
- ld a,45 ; was clear pressed
- call _setxxop1 ;
- call _cpop1op2 ;
- jp z,titlescreen ; quit
- jp edit_key_loop
-
- editup:
-
- ld hl,(row) ; are we at the top of the level
- ld de,(level) ;
- call _cphlde ;
- jp z,edit_key_loop ; return to key loop
- ld de,6 ; move to the next row
- sbc hl,de ;
- ld (row),hl ;
- call redraw ; draw out level
- jp edit_key_loop ; return to key loop
-
- editdown:
-
- ld hl,(level) ; are we at the bottom of the level
- ld de,1488 ;
- add hl,de ;
- ex de,hl ;
- ld hl,(row) ;
- call _cphlde ;
- jp z,edit_key_loop ; return to key loop
- ld de,6 ; move to previous row
- add hl,de ;
- ld (row),hl ;
- call redraw ; draw out level
- jp edit_key_loop ; return to key loop
-
- editleft:
-
- ld a,(col) ; are we at the very left
- cp 0 ;
- jp z,edit_key_loop ; return to key loop
- dec a ; move to next col
- ld (col),a ;
- call redraw ; draw out level
- jp edit_key_loop ; return to key loop
-
- editright:
-
- ld a,(col) ; are we at the very right
- cp 11 ;
- jp z,edit_key_loop ; return to key loop
- inc a ; move to next col
- ld (col),a ;
- call redraw ; draw out level
- jp edit_key_loop ; return to key loop
-
- putitem:
-
- ld a,(col) ; get col offset
- bit 0,a ; 0 means it is even
- jr nz,odd ; 1 means it is odd
-
- even:
-
- srl a ; divide col offset by 2
- ld d,0 ; add it to the row offset
- ld e,a ;
- ld hl,(row) ;
- add hl,de ;
- ld a,(hl) ; get item
- and $0F ; mask off item
- ld (hl),a ;
- ld a,(itemnum) ;
- sla a ; shift to the left 4 times
- sla a ;
- sla a ;
- sla a ;
- or (hl) ;
- ld (hl),a ; write item
- jp edit_key_loop ; return to key loop
-
- odd:
-
- srl a ; divide col offset by 2
- ld d,0 ; add it to the row offset
- ld e,a ;
- ld hl,(row) ;
- add hl,de ;
- ld a,(hl) ; get item
- and $F0 ; mask off item
- ld (hl),a ;
- ld a,(itemnum) ;
- or (hl) ;
- ld (hl),a ; write item
- jp edit_key_loop ; return to key loop
-
- changeitem:
-
- ld a,(itemnum) ; are we at the last item
- cp 5 ;
- jr z,nomore ;
- ld a,(itemnum) ; inc item num
- inc a ;
- ld (itemnum),a ;
- call redraw ; redraw level
- jp edit_key_loop ; return to key loop
-
- nomore:
-
- ld a,0 ; set itemnum to 0
- ld (itemnum),a ;
- call redraw ; redraw level
- jp edit_key_loop ; return to key loop
-
- ; draws out level compared to current offset
-
- redraw:
-
- call _grbufclr ; clear buffer
- ld hl,(row) ; start at current level offset
- ld de,plotsscreen ; copy to buffer
- ld b,8 ; 8 rows
-
- draw_loop1:
-
- push bc
- ld b,6 ; 6 bytes per row
-
- draw_loop2:
-
- push bc
- ld a,(hl) ; get data
- push hl ; save address to current level byte
- srl a ; shift right 4
- srl a ;
- srl a ;
- srl a ;
- call cpitem ; draw item
- inc de ; move to next byte in buffer
- pop hl ; restore address to current level byte
- ld a,(hl) ; get data
- push hl ; save address to current level byte
- and $0F ; mask off first 4 bits
- call cpitem ; draw item
- inc de ; move to next byte in buffer
- pop hl ; restore address to current level byte
- inc hl ; move to next byte in level
- pop bc
- djnz draw_loop2
-
- next_row:
-
- push hl
- ld hl,84 ; move to next row down in plotsscreen
- add hl,de ;
- ex de,hl ;
- pop hl ;
- pop bc ;
- djnz draw_loop1 ;
- ld de,plotsscreen ; move to col offset in buffer
- ld h,0 ;
- ld a,(col) ;
- ld l,a ;
- add hl,de ;
- ex de,hl ;
- ld a,(itemnum) ; get item
- call cpitem ; draw item
- call bufcpy ; copy buffer to screen
- ret
-
- cpitem:
-
- cp 0 ; is it a blank
- call z,drawblank ;
- cp 1 ; is it grass
- call z,drawgrass ;
- cp 2 ; is it a tree
- call z,drawtree ;
- cp 3 ; is it a small rock
- call z,drawrock1 ;
- cp 4 ; is it a large rock
- call z,drawrock2 ;
- cp 5 ; is it a gate
- call z,drawgate ;
- ret
-
- ; draws out item
-
- draw_item:
-
- push de ; save current address in plotsscreen
- ld b,8
-
- draw_item_loop:
-
- push bc
- push hl
- ld a,(hl)
- ld (de),a
- ld hl,12
- add hl,de
- ex de,hl
- pop hl
- inc hl
- pop bc
- djnz draw_item_loop
- pop de ; restore current address in plotsscreen
- ret
-
- ; sets up drawing for each item
-
- drawblank:
-
- ld hl,blank
- call draw_item
- ret
-
- drawgrass:
-
- ld hl,grass
- call draw_item
- ret
-
- drawtree:
-
- ld hl,tree
- call draw_item
- ret
-
- drawrock1:
-
- ld hl,rock1
- call draw_item
- ret
-
- drawrock2:
-
- ld hl,rock2
- call draw_item
- ret
-
- drawgate:
-
- ld hl,gate
- call draw_item
- ret
-
- ; get 1 initial from user, draw it to the current cursor location,
- ; and store the letter in the accumulator
-
- getinitial:
-
- ld hl,chars ; start of my own character map
- call drawchar ; draw out the starting char
- push hl ; save offset in char map
-
- iniloop:
-
- call _getk
- ld a,25 ; was up pressed
- call _setxxop1 ;
- call _cpop1op2 ;
- jr z,iniup ; move to next initial
- ld a,34 ; was down pressed
- call _setxxop1 ;
- call _cpop1op2 ;
- jr z,inidown ; move to previous initial
- ld a,21 ; was 2nd pressed
- call _setxxop1 ;
- call _cpop1op2 ;
- jr z,inidone ;
- jr iniloop
-
- iniup:
-
- pop hl ; get offset in char map
- ld a,(hl) ; are we at the last char?
- cp '9' ;
- jr z,noup ;
- inc hl ; move to next char
- call drawchar ; draw the char
- push hl ; save offset
- jr iniloop
-
- inidown:
-
- pop hl ; restore offset
- ld a,(hl) ; are we at the first char?
- cp 'A' ;
- jr z,nodown ;
- dec hl ; move to previous char
- call drawchar ; draw the char
- push hl ; save offset
- jr iniloop
-
- noup:
-
- ld hl,chars ; loop back to the start of the char map
- call drawchar ; draw the char
- push hl ; save offset
- jr iniloop
-
- nodown:
-
- ld hl,chars+35 ; loop back to the end of the char map
- call drawchar ; draw the char
- push hl ; save offset
- jr iniloop
-
- inidone:
-
- pop hl ; get rid of the offset
- ld a,(hl) ; save selected char in a
- ret
-
- drawchar:
-
- ld a,(hl) ; get the char
- call _vputmap ; draw it
- ld a,(pencol) ; get pencol
- sub 4 ; set it back to normal
- ld (pencol),a ; put it in pencol
- ret
-
- ; waits for any key yo be pressed
-
- waitforkey:
-
- call _getk ; wait for any key press
- ld a,0 ;
- call _setxxop1 ;
- call _cpop1op2 ;
- jr z,waitforkey ;
- ret ; return
-
- ; inverts 16x7 area at hl
-
- invert_area:
-
- push hl
- ld b,7
-
- invert_loop:
-
- push bc
- push hl
- ld b,4
-
- invert_loop2:
-
- ld a,(hl)
- cpl
- ld (hl),a
- inc hl
- djnz invert_loop2
- pop hl
- pop bc
- ld de,12
- add hl,de
- djnz invert_loop
- pop hl
- ret
-
- clearbottom:
-
- ld hl,plotsscreen+528
- ld de,plotsscreen+708
-
- clear_loop:
-
- ld (hl),0
- inc hl
- call _cphlde
- jr nz,clear_loop
- ret
-
- ; copy plotsscreen to lcd
- ; faster than _grbufcpy_v
-
- bufcpy:
-
- ld hl,plotsscreen
- ld b,40h
- di
- ld a,7
- call LCDBusy
- out (lcdinstport),a
- ld a,127
-
- bclcpy:
-
- push bc
- inc a
- ld (8012h),a
- call s7port10
- call lcdbusy
- out (lcdinstport),a
-
- ld a,20h
- call lcdbusy
- out (lcdinstport),a
- ld b,12
-
- bcl2cpy:
-
- ld a,(hl)
- inc hl
- call lcdbusy
- out (lcddata),a
- djnz bcl2cpy
- pop bc
- ld a,(8012h)
- djnz bclcpy
- ld a,5
- call lcdbusy
- out (lcdinstport),a
- ei
- ret
-
- lcdbusy:
-
- push af
- inc hl
- dec hl
- pop af
- ret
-
- s7port10:
-
- push af
- ld a,7
- call lcdbusy
- out (lcdinstport),a
- pop af
- ret
-
- ; title image
-
- title:
-
- .db $01,252,$03,$E0,$00,$00,$00,$00,$00,$00,$00,$00
- .db $07,$06,$02,$20,$00,$00,$00,$00,$00,$00,$00,$00
- .db $0C,$02,$02,$20,$00,$00,$00,$00,$00,$00,$00,$00
- .db $18,$02,$06,$20,$00,$00,$00,$00,$00,$00,$00,$00
- .db $11,$F6,$04,$60,$1F,$C0,$1F,$F8,$01,$FC,$01,$FF
- .db $11,$FC,$04,$40,$70,$60,$10,$0C,$07,$06,$07,$01
- .db $10,$38,$0D,$40,$C0,$30,$30,$04,$0C,$02,$0C,$01
- .db $10,$0C,$0A,$C1,$8F,$10,$23,$C4,$18,$E2,$08,$7B
- .db $19,$04,$0D,$81,$19,$50,$62,$44,$11,$E2,$08,$7E
- .db $0E,$54,$1B,$83,$19,$B0,$E2,$C6,$70,$02,$08,$0C
- .db $7B,$0C,$21,$86,$92,$51,$46,$8D,$A4,$06,$04,$04
- .db $4F,$AC,$20,$C9,$36,$2E,$45,$88,$33,$FD,$1F,$D4
- .db $C1,$DC,$40,$B2,$5C,$60,$47,$00,$29,$E6,$F3,$EC
- .db $80,$B2,$41,$02,$00,$C0,$80,$24,$30,$04,$00,$3C
- .db $C0,$61,$80,$00,$03,$88,$00,$61,$78,$01,$20,$18
- .db $60,$00,$29,$00,$E6,$02,$8F,$DA,$8F,$44,$10,$08
- .db $1E,$04,$10,$00,$01,$C8,$88,$05,$06,$28,$25,$10
- .db $0C,$11,$26,$08,$E1,$41,$98,$02,$01,$82,$18,$20
- .db $02,$86,$99,$23,$16,$23,$10,$00,$00,$44,$37,$C0
- .db $01,$29,$B0,$94,$0A,$18,$F0,$02,$00,$30,$E0,$00
- .db $01,$D8,$C0,$48,$08,$0D,$80,$07,$00,$09,$00,$00
- .db $01,$60,$80,$50,$00,$07,$00,$05,$00,$09,$00,$00
- .db $00,$E0,$00,$50,$00,$04,$00,$08,$80,$06,$00,$00
- .db $00,$C0,$00,$30,$00,$00,$00,$09,$80,$04,$00,$00
- .db $00,$80,$00,$20,$00,$00,$00,$07,$00,$00,$00,$00
-
- ; different sprites
-
- blank:
-
- .db %00000000
- .db %00000000
- .db %00000000
- .db %00000000
- .db %00000000
- .db %00000000
- .db %00000000
- .db %00000000
-
- grass:
-
- .db %00101010
- .db %10100000
- .db %00010101
- .db %01001000
- .db %00100010
- .db %00001100
- .db %01010001
- .db %01000010
-
- tree:
-
- .db %00011000
- .db %00011000
- .db %00111100
- .db %00111100
- .db %01111110
- .db %01111110
- .db %11111111
- .db %00011000
-
- rock1:
-
- .db %00000000
- .db %00000000
- .db %00001100
- .db %00010010
- .db %00100010
- .db %00100010
- .db %00011100
- .db %00000000
-
- rock2:
-
- .db %00000000
- .db %00111000
- .db %01000100
- .db %01010010
- .db %10100001
- .db %10000001
- .db %01000011
- .db %00111100
-
- gate:
-
- .db %00000000
- .db %01000010
- .db %01111110
- .db %01111110
- .db %01000010
- .db %01000010
- .db %01000010
- .db %01000010
-
- chars:
-
- .db "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
- .db "0123456789"
-
- editor:
-
- .db "Level Editor",0
-
- newstr:
-
- .db "New",0
-
- editstr:
-
- .db "Edit",0
-
- namestr:
-
- .db "Name:",0
-
- selectstr:
-
- .db "Edit:",0
-
- nomemstr:
-
- .db "Not Enough Memory",0
-
- nolevel1:
-
- .db "There arent any",0
-
- nolevel2:
-
- .db "levels to edit",0
-
- defaultprog:
-
- .db progobj,"ZSKIL"
-
- .end
- END