jeszcze tak apropo avr i osd
inicjalizacja:
.include "m644def.inc"
.def        zero =    r10
.def        one =    r11
.def        two =    r12
;-------------------------------------------------------------------------------;
;                                    Data Segment                                ;
;-------------------------------------------------------------------------------;
.dseg
.org    SRAM_Start
;-------------------------------------------------------------------------------
; Video Engine constants
;
;-------------------------------------------------------------------------------
.equ            SCREEN_WIDTH    =    40
;-------------------------------------------------------------------------------
; Video Engine variables
;
;-------------------------------------------------------------------------------
Line_Counter:    .byte    2
Line_Menu:        .byte    2
Line_Status:    .byte    2
;-------------------------------------------------------------------------------
; General
Display_Start:    .byte    2
Lines:            .byte    1
Menu_Buffer:    .byte    SCREEN_WIDTH*34
Status_Buffer:    .byte    SCREEN_WIDTH*2
Menu_Item:        .byte    1
Menu_Option:    .byte    1
;-------------------------------------------------------------------------------;
;                               Keyboard definitions                            ;
;-------------------------------------------------------------------------------;
.equ            START_Key    =    PD5
.equ            SELECT_Key    =    PD6
.equ            OPTION_Key    =    PD7
.equ            RESET_Key    =    PC7
;-------------------------------------------------------------------------------;
; party version
.equ            QMEG        =    PC4
.equ            MEMORY        =    PC2
.equ            EN_S        =    PA3
.equ            EN_C        =    PC6
.equ            SS_MODE        =    PA5
.macro        enable_covox
            sbi        PORTC,EN_C
.endmacro
.macro        disable_covox
            cbi        PORTC,EN_C
.endmacro
.macro        enable_stereo
            sbi        PORTA,EN_S
.endmacro
.macro        disable_stereo
            cbi        PORTA,EN_S
.endmacro
.macro        set_qmeg
            sbi        PORTC,QMEG
.endmacro
.macro        set_standard
            cbi        PORTC,QMEG
.endmacro
.macro        set_320k
            sbi        PORTC,MEMORY
.endmacro
.macro        set_1mb
            cbi        PORTC,MEMORY
.endmacro
.macro        set_d280
            sbi        PORTA,SS_MODE
.endmacro
.macro        set_d600
            cbi        PORTA,SS_MODE
.endmacro
;-------------------------------------------------------------------------------;
;                                    Code Segment                                ;
;-------------------------------------------------------------------------------;
.cseg
.overlap
.org    0
            rjmp    start
.org    INT1Addr
            rjmp    Video_Engine
.org    OC0Aaddr
            rjmp    Video_Engine
.org    SPMRaddr
.macro        wait
            ldi        @0,@1
ll:            dec        @0
            brne    ll
.endmacro
.org        0x40
MenuAddress:        .dw Menu
FontAddress:        .dw Fonts
start:        cli                                ; Disable Interrupts
            sbi        DDRC,RESET_Key
            cbi        PORTC,RESET_Key
            ldi        r16,low(RAMEND-64)
            ldi        r17,high(RAMEND-64)
            out        SPL,r16
            out        SPH,r17                    ; Setup Stack Pointer
            rcall    MCU_Setup                ; Setup ports
            rcall    SPI_Setup                ; Setup SPI
            rcall    INT_Setup                ; Setup INT1
            ldi        zl,low(Text*2)
            ldi        zh,high(Text*2)
            ldi        xl,low(Menu_Buffer)
            ldi        xh,high(Menu_Buffer)
            ldi        r18,4
l0:            ldi        r17,SCREEN_WIDTH
l1:            lpm        r16,z
            rcall    ATASCII2CHR
            adiw    zl,1
            st        x+,r16
            dec        r17
            brne    l1
            dec        r18
            brne    l0
            ldi        zl,low(Mode_OSD*2)        ;
            ldi        zh,high(Mode_OSD*2)        ;
            rcall    Init_VideoEngine        ; Restart Video Engine in specified mode
            enable_covox
;-------------------------------------------------------------------------------
; Initial setup of microcontroller
MCU_Setup:    ldi        r16,0b11111111
            out        DDRA,r16                ; set PORT A as output
            ldi        r16,0b01111111
            out        DDRC,r16                ; set PORT C as output
            ldi        r16,0b00000010
            out        DDRD,r16                ; set PORT D as input
            ldi        r16,0b00000000
            cbi        PORTC,PC7
            out        PORTD,r16
            clr        r16
            mov        zero,r16
            inc        r16
            mov        one,r16
            inc        r16
            mov        two,r16
            lds        r16,MCUCR
            ori        r16,1<<JTD
            sts        MCUCR,r16
            sts        MCUCR,r16
            ret
;-------------------------------------------------------------------------------;
; INT Setup
INT_Setup:    ldi        r16,0b00001000
            sts        EICRA,r16
            ldi        r16,0b00000010
            out        EIMSK,r16
            ret
;-------------------------------------------------------------------------------;
; SPI Setup
SPI_Setup:    sts        UBRR0H,zero
            sts        UBRR0L,zero
            sbi        DDRA, PA0            ; Setting the XCKn port pin as output, enables master mode.
            ldi        r16,(1<<UMSEL01)|(1<<UMSEL00)|(0<<UCPHA0)|(0<<UCPOL0)    ; Set MSPI mode of operation and SPI data mode 0.
            sts        UCSR0C,r16
            ldi        r16,(1<<TXEN0)            ; Enable transmitter.
            sts        UCSR0B,r16
            sts        UBRR0H,zero                ; Set baud rate.
            sts        UBRR0L,one                ; IMPORTANT: The Baud Rate must be set after the transmitter is enabled!
            ret
;-------------------------------------------------------------------------------
; Display Text
; R17        font raster line number
;-------------------------------------------------------------------------------
;-------------------------------------------------------------------------------
; ATASCII to charset code
; fonts i use are from atari 8bit computer, it uses special mapping for fonts 
; since there is only 6 bits for all letters and digits, thus some reorganisation 
; is required.
; i suppose one could convert data to standard ascii table before compilation, 
; but then diffrent fonts had to be converted pririor to compilation
; this way it was simplier
; R16        char code
ATASCII2CHR:
            cpi        r16,32
            brlo    ATASCII2CHR_p64
            cpi        r16,96
            brlo    ATASCII2CHR_m32
            ret
ATASCII2CHR_p64:
            subi    r16,-64
            ret
ATASCII2CHR_m32:
            subi    r16,32
            ret
;-------------------------------------------------------------------------------;
;                                     Libraries                                    ;
;-------------------------------------------------------------------------------;
.include    "video engine.asm"
.include    "video modes.asm"
;---------------------------------------------------------
;                0000000001111111111222222222233333333334;
;                1234567890123456789012345678901234567890;
Text:        .db " OSD Extension Atari configuration tool "
            .db "  Visit http://spiflash.org/atari/osd/  "
            .db "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"    ;                                        "
            .db "                     &2008  Candle'O'Sin"
            .db " Status:                                "
            .db "                                    test"
;---------------------------------------------------------
video_engine:
;-------------------------------------------------------------------------------
; Video Engine interrupt handler
Video_Engine:
            cli
            push    r16
            in        r16,SREG
            push    r16
            push    r17
            push    r18
            push    r19
            push    r20
            push    xh
            push    xl
            push    zh
            push    zl
            wait    r16,85
            lds        r16,Line_Counter
            lds        r17,Line_Counter+1
            add        r16,one
            adc        r17,zero
            sts        Line_Counter,r16
            sts        Line_Counter+1,r17
            lds        r2,Line_Menu
            lds        r3,Line_Menu+1
            cp        r16,r2
            cpc        r17,r3
            brlo    Video_Engine_End2
            lds        r2,Line_Status
            lds        r3,Line_Status+1
            cp        r16,r2
            cpc        r17,r3
            brsh    Video_Engine_Sync
            ;--------------------------------------------------------------------
            ; Horizontal Line starts here
            lds        r2,Line_Menu
            lds        r3,Line_Menu+1
            sub        r16,r2
            sbc        r17,r3
            ldi        xl,low(Menu_Buffer)
            ldi        xh,high(Menu_Buffer)
            sts        Display_Start,xl
            sts        Display_Start+1,xh
            ldi        xl,30
            sts        Lines,xl
            rcall    Horizontal_Line
            rjmp    Video_Engine_End2
Video_Engine_Vertical_Blank:
            sts        Line_Counter,zero
            sts        Line_Counter+1,zero
            rjmp    Video_Engine_End2
Video_Engine_Sync:
            sbis    PIND,3
            rjmp    Video_Engine_Sync1
            rjmp    Video_Engine_End2
Video_Engine_Sync1:
;            wait    r18,4
            sbis    PIND,3
            rjmp    Video_Engine_Vertical_Blank
Video_Engine_End2:
            pop        zl
            pop        zh
            pop        xl
            pop        xh
            pop        r20
            pop        r19
            pop        r18
            pop        r17
            pop        r16
            out        SREG,r16
            pop        r16
            sei
            reti
;-------------------------------------------------------------------------------
; Set Video Mode
; Z            Offset to video mode definition
Init_VideoEngine:
            cli
            ldi        r16,6
            ldi        xl,low(Line_Counter)
            ldi        xh,high(Line_Counter)
Init_VideoEngine_l1:
            lpm        r17,z
            adiw    zl,1
            st        x+,r17
            dec        r16
            brne    Init_VideoEngine_l1
            lpm        r16,z
            ldi        r17,0b00000000
            sts        EICRA,r17
            ldi        r17,0b00000010
            out        EIMSK,r17
            sei
            ret
;-------------------------------------------------------------------------------
; Horizontal Line
; R17:R16    Line number
Horizontal_Line:
            mov        r18,r16
            lds        xl,Display_Start
            lds        xh,Display_Start+1
            ldi        zl,low(Fonts*2)
            ldi        zh,high(Fonts*2)
            movw    r3:r2,zh:zl
            lsr        r17
            ror        r16
            lsr        r17
            ror        r16
            lsr        r17
            ror        r16
            lds        r17,Lines
            cp        r16,r17
            brlo    Display_Text_NoWarp
Display_Text_Warp:
            cbi        PORTA,0
            ret
Display_Text_NoWarp:
            ldi        r20,SCREEN_WIDTH
            mul        r16,r20
            add        xl,r0
            adc        xh,r1
            andi    r18,7
            ldi        r19,8
            ld        r16,x+
            add        r2,r16
            ld        r16,x+
            adc        r3,r16
            sbi        PORTA,0
Display_Text_l1:
            ld        r16,x+                ;2
            mul        r16,r19                ;4
            movw    zh:zl,r3:r2            ;5
            add        zl,r0                ;6
            adc        zh,r1                ;7
            add        zl,r18                ;8
            lpm        r16,z                ;11
            dec        r20                    ;12
            sts        UDR0,r16            ;14
            nop
            nop
            nop
            nop
            nop
            nop
            nop
            nop
            nop
            nop
            nop
            nop
            nop
            nop
            nop
            nop
            brne    Display_Text_l1        ;16
            wait    r16,6
            cbi        PORTA,0
            ret
;-------------------------------------------------------------------------------
; General purpose delay loop
; R16        clocks*3+6 to wait
Delay:        dec        r16
            brne    Delay
            ret
;-------------------------------------------------------------------------------
video_modes:
;-------------------------------------------------------------------------------;
;                             Video Mode definitions                                ;
;-------------------------------------------------------------------------------;
;-------------------------------------------------------------------------------
;Copper List for OSD 
Mode_OSD:    .dw    0                            ; Line_Counter
            .dw    40                            ; Line_Menu
            .dw    320                            ; Line_Status
;-------------------------------------------------------------------------------
myslalem ze poszlo sie kochac, ale jednak jest na dysku
						przechodze na tumiwisizm