OpenCores
URL https://opencores.org/ocsvn/z80soc/z80soc/trunk

Subversion Repositories z80soc

[/] [z80soc/] [trunk/] [V0.7.3/] [Software/] [C/] [testsys/] [crt0 copy.s] - Blame information for rev 46

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 46 rrred
;; module crt0.s for Z80SoC 0.7.3
2
;; ==============================
3
        .module crt0
4
       .globl   _main
5
        .area   _HEADER (ABS)
6
       .org #0
7
init:
8
        ;; Stack at the top of memory
9
        ld      sp,(#0x57D2)
10
    ;; Initialise global variables
11
        call    gsinit
12
        call    _main
13
        jp      _exit
14
 
15
        .area _CODE
16
        .area _CABS
17
 
18
        ;; Ordering of segments for the linker.
19
        .area   _HOME
20
        .area   _CODE
21
        .area   _GSINIT
22
        .area   _GSFINAL
23
 
24
        .area   _DATA
25
        .area   _BSEG
26
        .area   _BSS
27
        .area   _HEAP
28
 
29
        .area   _CODE
30
;       ---------------------------------
31
; Function putchar
32
; ---------------------------------
33
; Z80SoC V0.7.3
34
_putchar_start::
35
_putchar::
36
        push    ix
37
                        ; get output device port
38
        ld              a,(#0x57CD)
39
        or              a
40
    jr      z,printToVideo
41
    dec     a
42
    or      a
43
    jr      z,printToLCD
44
        ret     ; No more valid output peripherals available
45
 
46
printToLCD::
47
    ret     ; not implemented
48
 
49
printToVideo::
50
        ld              ix,#0
51
        add             ix,sp
52
        ld              a,4 (ix)
53
        cp              #0x0D
54
        jr              z,ignoreChar
55
        cp              #0x0A
56
        jr              z,newLine
57
        ld              hl,(#0x57D0)         ;get video address to print
58
        ld              (hl),a                       ;write char to video memory
59
        inc             hl
60
        ld              (#0x57D0),hl         ;save
61
 
62
    ; these part of the code will get the video coordenates x,y 
63
    ; and calculate the absolute VRAM address to store in 0x57D0
64
    ; If the cursors has reached the last line, it will not be increased,
65
    ; that is, cursor will stay pointing to last line.
66
updtcursorXY::
67
verifySameLine::
68
        ld              a,(#0x57CC)         ; get number of columns in video
69
        ld              b,a
70
        ld              a,(#0x57CF)         ; get current video X position
71
        inc             a
72
        cp              b                               ; compare to current column
73
        jr              c,sameLine                  ; did not find end of line
74
newLine::
75
        ld              a,(#0x57CB)                 ; Number of video lines
76
        ld              b,a
77
        ld              a,(#0x57CE)                 ; current video Y position
78
        inc             a
79
        cp              b
80
        jr              c,updtcursorY       ; not end of video screen
81
        dec             a                   ; end of video screen, keep cursor at last line
82
updtcursorY::
83
        ld              (#0x57CE),a                 ; save new video Y position
84
        call     _calcVAddress_start
85
        xor             a
86
sameLine::
87
        ld              (#0x57CF),a                 ;save new video X position
88
ignoreChar::
89
        pop             ix
90
        ret
91
_calcVAddress_start::
92
_calcVAddress:
93
;printvars.c:26: return (0x4000 + (readMemory(0x57CC) * y) + 0);
94
        ld              a,(#0x57CC)                     ; get number of columns in video
95
        ld              l,a
96
        ld              h,#0x00
97
        ld              a,(#0x57CE)                 ; get current video Y
98
        ld              c,a
99
        ld              b,#0x00
100
        call    multiply            ; call multiply routine, return value in hl
101
        push    hl
102
    ld      hl,(#0x57D4)        ;get VRAM address
103
    ld      b,h
104
    ld      c,l
105
    pop     hl
106
        add             hl,bc                       ; calc start of new line
107
        ld              (#0x57D0),hl        ; store new video address
108
        ret
109
_calcVAddress_end::
110
 
111
multiply::
112
        ;; multiply hl * bc and return in hl
113
        ld              a,b
114
        or              c                       ; is bc zero ?
115
        jr              nz,mul0         ; no
116
        ld              hl,#0x0000      ; X * 0 = zero
117
        ret
118
mul0::
119
        ld              d,h
120
        ld              e,l
121
mul::
122
        dec             bc                      ;dec bc does not update flags
123
        ld              a,b
124
        or              c                       ; is bc = zero ?
125
        ret             z                       ; return HL 
126
        add             hl,de
127
        jr              mul
128
putchar_end::
129
 
130
__clock::
131
        ret
132
 
133
_exit::
134
        ;; Exit - special code to the emulator
135
        jr              _exit
136
        .area   _GSINIT
137
gsinit::
138
                        ;; outdevice = 0x00 = video
139
        xor             a
140
        ld              (#0x57CD),a
141
        ld              a,#60                  ; screen lines
142
        ld              (#0x57CB),a
143
        ld              a,#80                  ; columns
144
        ld              (#0x57CC),a
145
        ld              hl,(#0x57D4)           ; get VRAM address
146
        ld              (#0x57D0),hl           ;current video memory address to print
147
        xor             a
148
        ld              (#0x57CE),a             ; video cursor y
149
        ld              (#0x57CF),a             ; video cursos x
150
        .area   _GSFINAL
151
        ret

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.