;+----------------------+ ;|Charput 1.6 | ;|By Justin TerAvest | ;| - The Backyard | ;| - Z80 Assembly Coders| ;|3/16/99 | ;+----------------------+ #include "asm86.h" #include "ti86asm.inc" .org _asm_exec_ram ld a,0 ld (numchars),a call _runindicoff ;turn off run indicator call _clrScrn ;clear screen ld hl,$0106 ld ($C00F),hl ld hl,String call _putps ld hl,$022C ;\ ld ($C37C),hl ; \ ld hl,Titlea ; \ call _vputs ; \ ld hl,$0823 ; -Draw the text. ld ($C37C),hl ; / ld hl,Titleb ; / call _vputs ;/ ld bc,$FC00 ;\ ld de,$003F ; \ ld hl,$0000 ; \ call FLine ; \ ld hl,$7E3F ; \ call FLine ;------ Draw the outside lines. ld de,$0000 ; / ld hl,$7E00 ; / call FLine ; / ld de,$7E3F ; / call FLine ;/ ld a,$40 ;-set RAM Page to 0 out (6),a ;/ sub a ;a = 0 (a-a) ld b,0 ;load 0 into d ld hl,$0B04 ;load 0B04 into hl ld ($C00F),hl ;load hl into the cursor position coords call _putmap ;disp a ld hl,$0804 ;load $0804 into hl ld ($C00F),hl ;load hl into the cursor position coords push bc ;put bc on the stack (save it) call dispHex ;The routine is at the bottom of the program ld a,b ;ld b into a call _putc ;disp a ld a,c ;ld c into a call _putc ;disp a pop bc ;put the "saved" bc back into bc Loop: ld c,b ld a,(numchars) cp 0 jr z,Loopb ld b,a ld hl,$0306 ld ($C00F),hl ld hl,$8013 Loopa: ld a,(hl) call _putc inc hl djnz Loopa Loopb: ld b,c call _getkey ;Getkey... duh cp kUp ;\ jr z,Up ;-If up was pressed, jump relative to Up: cp kDown ;\ jr z,Down ;-If down was pressed, jump relative to Down: cp kEnter ;\ jr z,Snd ;-If enter was pressed, jump relative to Snd: cp kExit ;\ jr z,Ext ;-if exit was pressed, jump relative to Ext: jr Loop ;if none of these happened, go back to Loop: Ext: ld hl,$0000 ld ($C00F),hl call _clrScrn ;clear screen ret ;exit program Up: dec b ;b-1 -> b ld a,b ;b -> a ld hl,$0B04 ;$0B04 -> hl ld ($C00F),hl ;hl -> ($C00F) call _putmap ;disp a ld hl,$0804 ;$0804 - > hl ld ($C00F),hl ;hl -> ($C00F) push bc ;put bc on stack (save) call dispHex ;call the routine at the bottom of the program ld a,b ;b -> a call _putc ;disp a ld a,c ;c -> a call _putc ;disp a pop bc ;put bc back jr Loop ;go back to Loop: Down: inc b ;b+1 -> b ld a,b ;b -> a ld hl,$0B04 ;$0B04 -> hl ld ($C00F),hl ;hl -> ($C00F) call _putmap ;disp a ld hl,$0804 ;$0804 -> hl ld ($C00F),hl ;hl -> ($C00F) push bc ;put bc on stack call dispHex ; ld a,b ;b -> a call _putc ;disp a ld a,c ;c -> a call _putc ;disp a pop bc ;put bc back jr Loop ;go back to Loop: Snd: ld a,(numchars) inc a ld (numchars),a ld c,b ld a,(numchars) ld b,a ld hl,$8012 Loopaa: inc hl djnz Loopaa ld b,c ld a,b ld (hl),a ld a,(numchars) ;numchars -> a ld ($8012),a ;a -> ($8012) cp $11 jr z,Ext jp Loop ;jumps relative to Loop: dispHex: ld b,a ;My display routine for the hexcodes and %00001111 ;I WILL NOT comment it unless you really need it to learn ASM. ld d,a ld a,b ;If you want to use it, please let me call $4383 ;know and mention me in your and %00001111 ;README.txt file. ld e,a cp $0A jp p,overa add a,'0' jp overb overa: sub $0A add a,'A' overb: ld b,a ld a,d cp $0A jp p,overc add a,'0' jp overd overc: sub $0A add a,'A' overd: ld c,a ret Titlea: .db "Charput 1.6",0 Titleb: .db "By Justin TerAvest",0 ; ; FASTLINE 1.0 ; ; BRESENHAM'S LINE ALGORITHM ; by Jimmy M†rdell ; ; Parameters: BC = memory area to draw line (usually $FC00) ; DE,HL = coordinates of line (D,E)-(H,L) ; 0 < D,H < 128, 0 < E,L < 64 ; ; Code size: 145 bytes (excluding FindPixel) ; ; Registers: AF destroyed. ; ; Performance: 4 times faster than Stephane Jantzens line routine ; ; Delta_X > Delta_Y => innerloop = 98.50 T states ; Delta_Y > Delta_X => innerloop = 106.75 T states ; FLine: push bc push de push hl push bc ld a,h cp d jr nc,DXpos ex de,hl DXpos: ld b,d ld c,e pop de push hl call FindPixel add hl,de ex (sp),hl ld e,c ld c,a ld a,h sub b ld b,a ld a,l sub e ld de,16 jr nc,DYpos neg ld de,-16 DYpos: push af sub b jr nc,DY_Greater add a,a neg ld (x_ai+1),a pop af add a,a ld (XDNeg+1),a sub b pop hl push af ld a,c or (hl) ld (hl),a pop af bit 7,a jr nz,XDNeg XNewRow: add hl,de x_ai: sub 0 push af rrc c jr nc,XNoWrap1 inc hl XNoWrap1: ld a,c or (hl) ld (hl),a pop af dec b jr z,LineDone jr nc,XNewRow XDNeg: add a,0 push af rrc c jr nc,XNoWrap2 inc hl XNoWrap2: ld a,c or (hl) ld (hl),a pop af dec b jr z,LineDone jr c,XNewRow jr XDNeg DY_Greater: neg add a,a ld (YNoWrap+1),a ld a,b add a,a ld (YDNeg+1),a pop hl sub h ld b,h pop hl push af ld a,c or (hl) ld (hl),a pop af YRepeat: bit 7,a jr nz,YDNeg rrc c jr nc,YNoWrap inc hl YNoWrap: add a,0 jr YPlot YDNeg: add a,0 YPlot: add hl,de push af ld a,c or (hl) ld (hl),a pop af djnz YRepeat LineDone: pop hl pop de pop bc ret ; ; This is your default FindPixel routine. Can be exchanged with ; the famous Eble-Yopp... FindPixel routine. ; FindPixel: push bc push de ld hl,ExpTable ld d,0 ld a,b and $07 ld e,a add hl,de ld e,(hl) ld h,d srl b srl b srl b ld a,c add a,a add a,a ld l,a add hl,hl add hl,hl ld a,e ld e,b add hl,de pop de pop bc ret ExpTable: .db $80,$40,$20,$10,$08,$04,$02,$01 numchars: .db 0 String: .db 2,"U:" .end