if 1
*****************
* prints r0 hex at cursor
printchar       reg 4
null            reg 3
PHhelp1         reg 2
PHHelp          reg 1
PrintHex::      PUSH r0,r1,r2,r3,r4
                movei #"0",null
                movei #PrintChar,printchar
                move r0,r1

                REPT 4
                  rorq #24,r1
                  move r1,r0
                  shlq #24,r0     ; first byte up
                  move r0,r2
                  shrq #28,r0     ; high nibble down
                  shlq #4,r2      ; low nibble up
                  shrq #28,r2     ; low nibble down
                  cmpq #10,r0
                  jr n,._1@
                  add null,r0
                    addq #7,r0
._1@              cmpq #10,r2
                  jr n,._2@
                  add null,r2
                    addq #7,r2
._2@              JSR (printchar)
                  move r2,r0
                  JSR (printchar)
                  INC@
                ENDR
                POP r4,r3,r2,r1,r0
                RTS
                unreg PHHelp,PHhelp1,null,printchar
*****************
endif
****************************
* Textscreen with 8x8-Font *
* created : 29.06.95       *
* (c) Bastian Schick       *
****************************
;global EQUs
; max_x, max_y must be preset !
;global registers
;Cursor.a       
;ScreenPtr.a                    ; must be initialized !

********************
* Print char in r0 *
********************
PChelp1         reg 3
PChelp          reg 2
ptr             reg 1
CharPtr         reg 0

PrintChar::     PUSH r1,r2,r3
                movei #ASCII+8,ptr
                shlq #24,CharPtr
                movefa Cursor.a,PChelp          ; get current cursor
                shrq #24-3,CharPtr              ; (r0 and $ff)*16
                shrq #16,PChelp                 ; get x
                add ptr,CharPtr
                movefa ScreenPtr.a,ptr
                add PChelp,ptr
                movefa Cursor.a,PChelp
                movei #max_x<<3,PChelp1         ; bytes per line*8
                mult PChelp1,PChelp
                shrq #3,PChelp1                 ; = bytes per line
                add PChelp,ptr

                load (CharPtr),PChelp          ; get 4 bytes of char
                addq #4,CharPtr
                REPT 4
                  rorq #24,PChelp               ; first byte down
                  storeb PChelp,(ptr)
                  add PChelp1,ptr
                ENDR
                load (CharPtr),PChelp
                REPT 3
                  rorq #24,PChelp               ; first byte down
                  storeb PChelp,(ptr)
                  add PChelp1,ptr
                ENDR
                rorq #24,PChelp
                storeb PChelp,(ptr)
                movefa Cursor.a,PChelp
                move PChelp,r0
                shlq #16,r0
                shrq #16,PChelp
                shrq #16,r0
                addq #1,PChelp
                cmp PChelp,PChelp1
                jr nz,._1
                nop
                  moveq #0,PChelp
                  movei #max_y,PChelp1
                  addq #1,r0
                  cmp PChelp1,r0
                  jr nz,._1
                  nop
                    moveq #0,r0
._1             shlq #16,PChelp
                or PChelp,r0
                moveta r0,Cursor.a
                POP r3,r2,r1
                RTS
                ALIGN 2
                unreg CharPtr,ptr,PChelp,PChelp1
****************
* prints r0 dez with 6 digits
LOOP            reg 5
PDhelp2         REG 4
PDhelp1         REG 3
printchar       REG 2
PDhelp          REG 1

PrintDez6::     PUSH r1,r2,r3,r4,r5
                movei #PrintChar,printchar
                move r0,PDhelp
                movei #10000,PDhelp1
                movei #10,PDhelp2
                movei #.loop,LOOP
                movei #"0"-1,r0
.loop             sub PDhelp1,PDhelp
                  jump nn,(LOOP)
                  addq #1,r0
                JSR (printchar)
                add PDhelp1,PDhelp
                div PDhelp2,PDhelp1
                cmpq #1,PDhelp1
                movei #"0"-1,r0
                jump nz,(LOOP)
                nop
                addq #1,r0
                add PDhelp,r0
                JSR (printchar)
                POP r5,r4,r3,r2,r1
                RTS
                
UNREG printchar,PDhelp,PDhelp1,PDhelp2,LOOP

****************
* prints r0 dez with 3 digits
PDhelp1         REG 3
printchar       REG 2
PDhelp          REG 1
PrintDez3::     PUSH r1,r2,r3
                movei #PrintChar,printchar
                move r0,PDhelp
                movei #100,PDhelp1
                movei #"0"-1,r0
.loop           sub PDhelp1,PDhelp
                jr nn,.loop
                addq #1,r0
                JSR (printchar)
                add PDhelp1,PDhelp
                movei #PrintDez2cont,r0
                POP PDhelp1
                jump (r0)
                nop
                
UNREG printchar,PDhelp,PDhelp1
****************
* prints r0 dez with 2 digits
printchar       reg 2
PDhelp          reg 1

PrintDez2::     PUSH r1,r2
                movei #PrintChar,printchar
                move r0,r1
PrintDez2cont   movei #"0"-1,r0
.loop           subq #10,r1
                jr nn,.loop
                addq #1,r0
                addq #10,r1
                JSR (printchar)
                movei #"0",r0
                add r1,r0
                JSR (printchar)
                POP r2,r1
                RTS
UNREG printchar,PDhelp
****************
* prints text at r0 (C-style)
* text must be Long-aligned
****************
EXIT            reg 5
LOOP            reg 4
PRhelp          reg 3
printchar       reg 2
ptr             reg 1
PrintR0::       PUSH r1,r2,r3,r4,r5
                move r0,ptr
                movei #PrintChar,printchar
                movei #.loop,LOOP
                movei #.exit,EXIT
                load (ptr),PRhelp
.loop           addq #4,ptr
                REPT 4
                  rorq #24,PRhelp
                  nop
                  move PRhelp,r0
                  shlq #24,r0
                  jump z,(EXIT)
                  shrq #24,r0     ; get byte
                  JSR (printchar)
                ENDR
                jump (LOOP)
                load (ptr),PRhelp

.exit           POP r5,r4,r3,r2,r1
                RTS
                unreg EXIT,LOOP,PRhelp,printchar,ptr
