Login

Subversion Repositories NedoOS

Rev

Rev 1952 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

        DEVICE ZXSPECTRUM128
        include "../_sdk/sys_h.asm"

INTSTACK=0x3800

        org PROGSTART
begin
        ;ld ix,(1<<9)+(2<<5)+12
        ;ld hl,(7<<11)+(34<<5)+(23/2) ;ix=date, hl=time
        ;OS_SETTIME

        ;ld e,6 ;textmode
        ;OS_SETGFX
        call initstdio

        ld a,0x01 ;ld bc
        ld (callcommand),a
        ld hl,tfreetime
        call prtext
        call looper
        call prdword_dehl
        call crlf

        ld a,0xcd ;call
        ld (callcommand),a
        ld hl,tfreetimeos
        call prtext
        call looper
        call prdword_dehl
        call crlf

        call swapimer
       
        call yieldgetkeyloop

        QUIT
       
looper        
        halt
        call swapimer
        ld hl,timeloop
        ld (on_int_q),hl
        ld de,0
        ld hl,timeloopq
        ld hx,8+1
        ds 0x200-1-$
        halt ;quit to timeloop
timeloop
        ld (on_int_q),hl
        ds 256-4-4
        inc de
        jp timeloop
timeloopq
        ld hl,(on_int_jp)
;d,e,l=NOPs
        ld h,e
        ld e,d
        ld d,0
;dehl=NOPs
        dup 3
        srl d
        rr e
        rr h
        rr l
        edup
        push de
        push hl
        call swapimer
        pop hl
        pop de
        ret

prtext
;hl=text
        push hl
        call strlen ;hl=length
        pop de ;de=text
        jp sendchars

strlen
;hl=str
;out: hl=length
        xor a
        ld b,a
        ld c,a ;╤З╤В╨╛╨▒╤Л ╤В╨╛╤З╨╜╨╛ ╨╜╨░╨╣╤В╨╕ ╤В╨╡╤А╨╝╨╕╨╜╨░╤В╨╛╤А
        cpir ;╨╜╨░╨╣╨┤╤С╨╝ ╨╛╨▒╤П╨╖╨░╤В╨╡╨╗╤М╨╜╨╛, ╨╡╤Б╨╗╨╕ ╨┤╨╗╨╕╨╜╨░=0, ╤В╨╛ bc=-1 ╨╕ ╤В.╨┤.
        ld hl,-1
        or a
        sbc hl,bc
        ret

swapimer
        di
        ld de,0x0038
        ld hl,oldimer
        ld bc,3
swapimer0
        ld a,(de)
        ldi ;[oldimer] -> [0x0038]
        dec hl
        ld (hl),a ;[0x0038] -> [oldimer]
        inc hl
        jp pe,swapimer0
        ei
        ret
oldimer
        jp on_int ;╨╖╨░╨╝╨╡╨╜╨╕╤В╤Б╤П ╨╜╨░ ╨║╨╛╨┤ ╨╕╨╖ 0x0038
        jp 0x0038+3

on_int
;restore stack with de
        EX DE,HL
        EX (SP),HL ;de="hl", ╨▓ ╤Б╤В╨╡╨║╨╡ "de"
        LD (on_int_jp),HL
        LD (on_int_sp),SP
        LD SP,INTSTACK
        push af
        push bc
        push de ;"hl"
        exx
        ex af,af' ;'
        push af
        push bc
        push de
        push hl
        push ix
        push iy
callcommand=$
        call oldimer ;ei ;╨░ ╤З╤В╨╛ ╨╡╤Б╨╗╨╕ ╨▓╤Л╨╣╨┤╨╡╨╝ ╨┐╨╛╨╖╨┤╨╜╨╛ (╨┐╨╛ yield)? ╨╜╨░╨┤╨╛ ╨▓ ╨║╨╛╨╜╤Ж╨╡ ╨╛╨▒╤А╨░╨▒╨╛╤В╤З╨╕╨║╨░ ╤Г╨▒╤А╨░╤В╤М ei, ╨╜╨╛ ╨╕ ╤Н╤В╨╛ ╨╜╨╡ ╨┐╨╛╨╝╨╛╨╢╨╡╤В, ╤В.╨║. yield ╤Б╨╡╨╣╤З╨░╤Б ╤Б ╨▓╨║╨╗╤О╤З╨╡╨╜╨╜╤Л╨╝╨╕ ╨┐╤А╨╡╤А╤Л╨▓╨░╨╜╨╕╤П╨╝╨╕!!!      

        pop iy
        pop ix
        pop hl
        pop de
        pop bc
        pop af
        ex af,af' ;'
        exx
        pop hl
        pop bc
        pop af        
on_int_sp=$+1
        ld sp,0
        pop de
        ei
        dec hx
on_int_jp=$+1
        jp nz,0;jp 0
on_int_q=$+1
        jp timeloop ;/timeloopq

crlf
        ld hl,2 ;hl=length
        ld de,tcrlf ;de=text
        jp sendchars

tcrlf
        db 13,10
tfreetime
        db "Free time with generic user INT handler (NOPs)=",0
tfreetimeos
        db "Free time with generic user INT handler (NOPs)=",0
       
        include "../_sdk/stdio.asm"
        include "../_sdk/prdword.asm"
end
        savebin "freetime.com",begin,end-begin

        LABELSLIST "../../us/user.l",1