From: Jon Langseth Date: Mon, 23 Jan 2017 17:49:13 +0000 (+0100) Subject: Some Z80 ASM for CP/M X-Git-Url: https://git.defcon.no/?a=commitdiff_plain;h=4ac76fc65056e1aaa0e1a5a83284d1fc63da733d;p=z80cpm Some Z80 ASM for CP/M --- 4ac76fc65056e1aaa0e1a5a83284d1fc63da733d diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..eee4db0 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.hex diff --git a/tiktok.asm b/tiktok.asm new file mode 100644 index 0000000..bdcdfaa --- /dev/null +++ b/tiktok.asm @@ -0,0 +1,67 @@ +; tiktok.asm +; ASM dialect is for crasm/z80, producing Intel HEX. +; Compile using "crasm -o tiktok.hex tiktok.asm" and transfer +; to CP/M system for final conversion to COM file using LOAD.COM +; +; A sample program that uses a busy-waiting spinloop +; to produce 1ms delays. 5*200 iterations of calls to +; the delay loop is made, to provide a 1sec delay per "Tick". +; 60 iterations of printint "Tick" to the console is done +; for a full minute of waiting time. +; Console output is done using CP/M BDOS call 9 (C_WRITRSTR) + +CPU Z80 +OUTPUT HEX + +; CP/M constants used +STROUT EQU 9 +BDOS EQU 5 + +; Start COM file at TPA start (Origin 0x100) +* = $100 +START LD DE, STARTMSG + LD C, STROUT + CALL BDOS + + LD A, 60 +LOOP PUSH AF + + LD DE, MESSAGE + LD C, STROUT + CALL BDOS + + LD B, 5 ; 5 * 200 msec = 1000ms = 1 sec :P +SEC LD A, 200 + CALL DELAY + DEC B + JR NZ, SEC + + POP AF + DEC A + JR NZ, LOOP + + LD DE, STOPMSG + LD C, STROUT + CALL BDOS + + RET + +; Delay routine, A register contains number of Delay iterations. +; Does not clobber, but A is reduced to zero on completion +; Values tried (may be good) for 7.3728MHz: C=13, B=44 +DELAY PUSH BC ; Save B and C registers +DLY_START LD C, 13 ; Coarse factor +DLY_LOOPO LD B, 44 ; Fine factor +DLY_LOOPI DJNZ DLY_LOOPI ; Decrement B until BZero + DEC C ; Decrement C .. + JR NZ, DLY_LOOPO ; .. until zero + DEC A ; Do next main iteration + JR NZ, DLY_START ; until given numer is zero + POP BC ; Restore B and C registers + RET ; Return from delay. + +; String constants here, to avoid having them clobber $100H +; Note CP/M BDOS call 9 format, $ is string terminator. +STARTMSG ASC "Timertest\r\n$" +MESSAGE ASC "Tick\r\n$" +STOPMSG ASC "Done\r\n$"