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

Subversion Repositories z80soc

[/] [z80soc/] [trunk/] [V0.7.3/] [Software/] [C/] [testsys/] [crt0.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
    pop     ix
45
        ret     ; No more valid output peripherals available
46
 
47
printToLCD::
48
    pop     ix
49
    ret     ; not implemented
50
 
51
printToVideo::
52
        ld              ix,#0
53
        add             ix,sp
54
        ld              a,4 (ix)
55
        cp              #0x0D
56
        jr              z,ignoreChar
57
        cp              #0x0A
58
        ld              hl,(#0x57D0)         ;get video address to print
59
        jr              z,newLine
60
        ld              (hl),a                       ;write char to video memory
61
        inc             hl
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
    ; now need to calcualte absolute vram addres on next line
85
    ld      a,(#0x57CF)         ;get current X position
86
    ld      c,a
87
    xor     a
88
    ld      b,a
89
    sbc     hl,bc                ;set vram to start of same line
90
    ld      a,(#0x57CC)
91
    ld      c,a
92
    add     hl,bc                ;next line in the vram
93
        ;call     _calcVAddress_start
94
        xor             a
95
sameLine::
96
    ld      (#0x57D0),hl
97
        ld              (#0x57CF),a                 ;save new video X position
98
ignoreChar::
99
        pop             ix
100
        ret
101
_calcVAddress_start::
102
_calcVAddress:
103
;printvars.c:26: return (0x4000 + (readMemory(0x57CC) * y) + 0);
104
        ld              a,(#0x57CC)                     ; get number of columns in video
105
        ld              l,a
106
        ld              h,#0x00
107
        ld              a,(#0x57CE)                 ; get current video Y
108
        ld              c,a
109
        ld              b,#0x00
110
        call    multiply            ; call multiply routine, return value in hl
111
        push    hl
112
    ld      hl,(#0x57D4)        ;get VRAM address
113
    ld      b,h
114
    ld      c,l
115
    pop     hl
116
        add             hl,bc                       ; calc start of new line
117
        ld              (#0x57D0),hl        ; store new video address
118
        ret
119
_calcVAddress_end::
120
 
121
multiply::
122
        ;; multiply hl * bc and return in hl
123
        ld              a,b
124
        or              c                       ; is bc zero ?
125
        jr              nz,mul0         ; no
126
        ld              hl,#0x0000      ; X * 0 = zero
127
        ret
128
mul0::
129
        ld              d,h
130
        ld              e,l
131
mul::
132
        dec             bc                      ;dec bc does not update flags
133
        ld              a,b
134
        or              c                       ; is bc = zero ?
135
        ret             z                       ; return HL 
136
        add             hl,de
137
        jr              mul
138
putchar_end::
139
 
140
_exit::
141
        jr              _exit
142
        .area   _GSINIT
143
gsinit::
144
                        ;; outdevice = 0x00 = video
145
        xor             a
146
        ld              (#0x57CD),a
147
        ld              a,#60                  ; screen lines
148
        ld              (#0x57CB),a
149
        ld              a,#80                  ; columns
150
        ld              (#0x57CC),a
151
        ld              hl,(#0x57D4)           ; get VRAM address
152
        ld              (#0x57D0),hl           ;current video memory address to print
153
        xor             a
154
        ld              (#0x57CE),a             ; video cursor y
155
        ld              (#0x57CF),a             ; video cursos x
156
        .area   _GSFINAL
157
        ret

powered by: WebSVN 2.1.0

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