]> git.defcon.no Git - z80cpm/blob - tiktok.asm
An experiment in reading files on CP/M
[z80cpm] / tiktok.asm
1 ; tiktok.asm
2 ; ASM dialect is for crasm/z80, producing Intel HEX.
3 ; Compile using "crasm -o tiktok.hex tiktok.asm" and transfer
4 ; to CP/M system for final conversion to COM file using LOAD.COM
5 ;
6 ; A sample program that uses a busy-waiting spinloop
7 ; to produce 1ms delays. 5*200 iterations of calls to
8 ; the delay loop is made, to provide a 1sec delay per "Tick".
9 ; 60 iterations of printint "Tick" to the console is done
10 ; for a full minute of waiting time.
11 ; Console output is done using CP/M BDOS call 9 (C_WRITRSTR)
12
13 CPU Z80
14 OUTPUT HEX
15
16 ; CP/M constants used
17 STROUT EQU 9
18 BDOS EQU 5
19
20 ; Start COM file at TPA start (Origin 0x100)
21 * = $100
22 START LD DE, STARTMSG
23 LD C, STROUT
24 CALL BDOS
25
26 LD A, 60
27 LOOP PUSH AF
28
29 LD DE, MESSAGE
30 LD C, STROUT
31 CALL BDOS
32
33 LD B, 5 ; 5 * 200 msec = 1000ms = 1 sec :P
34 SEC LD A, 200
35 CALL DELAY
36 DEC B
37 JR NZ, SEC
38
39 POP AF
40 DEC A
41 JR NZ, LOOP
42
43 LD DE, STOPMSG
44 LD C, STROUT
45 CALL BDOS
46
47 RET
48
49 ; Delay routine, A register contains number of Delay iterations.
50 ; Does not clobber, but A is reduced to zero on completion
51 ; Values tried (may be good) for 7.3728MHz: C=13, B=44
52 DELAY PUSH BC ; Save B and C registers
53 DLY_START LD C, 13 ; Coarse factor
54 DLY_LOOPO LD B, 44 ; Fine factor
55 DLY_LOOPI DJNZ DLY_LOOPI ; Decrement B until BZero
56 DEC C ; Decrement C ..
57 JR NZ, DLY_LOOPO ; .. until zero
58 DEC A ; Do next main iteration
59 JR NZ, DLY_START ; until given numer is zero
60 POP BC ; Restore B and C registers
61 RET ; Return from delay.
62
63 ; String constants here, to avoid having them clobber $100H
64 ; Note CP/M BDOS call 9 format, $ is string terminator.
65 STARTMSG ASC "Timertest\r\n$"
66 MESSAGE ASC "Tick\r\n$"
67 STOPMSG ASC "Done\r\n$"