Hi,
I thought I'd start a thread for ZX80 specific dev talk (it may be an echo chamber) for the ZX80 and compatible clones.
I'll post C, BASIC and Assembly [in C wrapper] snippets here for people to digest, re-use, improve etc...
Thanks,
Shaun.
ZX80 development thread
Re: ZX80 development thread
I think that's a great idea - you may just spark an interest in coding for this challenging machine!
Re: ZX80 development thread
Yesss,
Wasn't there a wait for keypress for ZX80 in assembly from you somewhere around?
I'm searching for this...
Kind regards Paul
Wasn't there a wait for keypress for ZX80 in assembly from you somewhere around?
I'm searching for this...
Kind regards Paul
In theory, there is no difference between theory and practice. But, in practice, there is.
Re: ZX80 development thread
I'll start with my generic CLS() routine in z88dk (C):
In usual assembly, you can remove the exx instructions at the start and end of each block (this is required because of the way that C works; preserve the registers before the custom assembly to restore them before returning from the C function wrapper). Calling location $0747 places the cursor at effective position zero of the DFILE (well, position zero must always be a newline, so the next one).
Regards,
Shaun
Code: Select all
/**
* Clears the screen
*
* @author sbebbington
* @date 22 Aug 2017
* @version 1.1a
*/
void cls()
{
__asm
exx
ld hl, ($400c)
ld bc, $0300
ld d, $21
inc l
CLS:
dec d
jr z, NEWLINE
ld (hl), $00
DECC:
inc hl
dec c
jr z, DECB
jr CLS
DECB:
dec b
jr z, EXIT
jr CLS
NEWLINE:
ld (hl), $76
ld d, $21
jr DECC
EXIT:
call $0747
exx
__endasm;
}
Regards,
Shaun
-
- Posts: 330
- Joined: Sat Sep 27, 2014 8:02 pm
- Location: Stockholm, Sweden
Re: ZX80 development thread
For cycle-counting madness and getting a stable picture, have a look at my sources to Metropolis
/Adam
Re: ZX80 development thread
Probably not the best part of the code, but if you'll find interesting following is the raw piece of code I used to read keyboard in Z80 flickerfree version of 1K real chess:
Code: Select all
loopkeyread:
; DISPLAY SCREEN BLINKING
push bc
call display_blinking_cursor
pop bc
ld b,$7F ; first time load of keyboard row pointer
ld hl,tablekeyactions-2
ciclonokeypressed:
inc hl ;T6x2
inc hl
ld a,b ;T4
in a,($FE) ;T11
or $e0 ;T7 OR 11100000 (since US based have bit 6 reset, but also different video settings)
inc a ;T4
jr nz,keypressed ;T7/12 $FF+1 = 0 = no key pressed
rrc b ;T8 8 bit rotation to the right
jr nc,loopkeyreadnokeypressed ;T7/12
jr ciclonokeypressed ;T12
keypressed:
; one key of this row was pressed, process it!
ld a,c
or a
jr nz,loopkeyread ; before another key this one should be left unpressed
inc c ; flag for debouncing (in reality not repeating, not really debouncing)
-> process action pointed by hl register...
-> ...
;-------------
djnz_wait1 = 92 ;92
djnz_wait2 = 40 ;47
display_blinking_cursor:
call blinkloop
ld b,djnz_wait1-djnz_wait2 ;92 ;T 92*13=1196
wait1: djnz wait1 ;T13
blinkloop:
; invert_char (>>>can be used to loose time between the two calls?)
ld a,(de)
xor 128
ld (de),a
push de
out ($FF),a
ld a,$E8
ld b,$19 ; B=1 'row' for top border (of C=MARGIN_TOP lines), +24 ($18) rows of 8 lines
ld c,$38 ; MARGIN_TOP equ $-1
ld hl,dfile+$8000
call $01B0
ld a,$EB
inc b ; B=1 'row' for bottom border (of C=MARGIN_BOTTOM lines)
ld c,$37 ; MARGIN_BOTTOM equ $-1
ret z ; delay 5 T-states for good
; ... dec c ; like ld c,$37 since c is still $38 but 1 byte less (and 4 instead of 7 T-States)
; ... and (hl) ; delay 7 T-States (and still 1 bytes) -> 7T+5T almost 4T+7T and 1 byte less
dec hl ; why?
call $01B0
in a,($FE) ; <<< double if input keyboard...
ld b,djnz_wait2 ;T 611+576+x
wait2: djnz wait2 ;T13
pop de
ret