home *** CD-ROM | disk | FTP | other *** search
/ Whiteline: Alpha / Whiteline Alpha.iso / tools / cpx_acc / cpxbasic / sources / cpx_bios.s < prev    next >
Encoding:
Text File  |  1994-09-22  |  10.9 KB  |  491 lines

  1. ;------------------------------------------------------------------
  2. ;
  3. ;        Basic-Input/Output    (BIOS)
  4. ;
  5. ;------------------------------------------------------------------
  6.  
  7. ;------------------------------------------------------------------
  8. ; wenn EXTRAFONT auf einen Wert!=0 gesetzt wird, wird nicht der
  9. ; Systemfont verwendet, sondern ein eigener
  10. ; d.h. kein LINE-A, dafür länger
  11. ;------------------------------------------------------------------
  12.  
  13.             .text
  14.             .mc68000
  15.  
  16.             .import font8x8
  17.             .import memcpy
  18.             .import ctrl
  19.             .import WaitBASIC
  20.             .import do_draw
  21.             .import DirtyScreen
  22.  
  23. ;------------------------------------------------------------------
  24.  
  25.             NULL_KENN    =    $87916543    ; 4-Byte-Kennung
  26.  
  27. ;------------------------------------------------------------------
  28. ; Stellt fest, ob ein vorangegangenes Null-Byte den String terminiert
  29. ; int is0byte(char *);
  30. ;------------------------------------------------------------------
  31.  
  32.             .xref is0byte
  33.  
  34. is0byte:    moveq    #0,D0
  35.             bsr.s    is0byte__
  36.             bne.s    is0_end
  37.             moveq    #4,D0
  38. is0_end:    rts
  39.  
  40. is0byte__:    cmp.b    #(NULL_KENN>>24)&$FF,(A0)
  41.             bne.s    .fa
  42.             cmp.b    #(NULL_KENN>>16)&$FF,1(A0)
  43.             bne.s    .fa
  44.             cmp.b    #(NULL_KENN>>8)&$FF,2(A0)
  45.             bne.s    .fa
  46.             cmp.b    #NULL_KENN&$FF,3(A0)
  47. .fa:        rts
  48.  
  49. ;------------------------------------------------------------------
  50. ; legt hinter einem Null-Byte eine Kennung ab
  51. ; void make0byte(char *);
  52. ;------------------------------------------------------------------
  53.  
  54.             .xref make0byte
  55.  
  56. make0byte:    move.b    #(NULL_KENN>>24)&$FF,(A0)
  57.             move.b    #(NULL_KENN>>16)&$FF,1(A0)
  58.             move.b    #(NULL_KENN>>8)&$FF,2(A0)
  59.             move.b    #NULL_KENN&$FF,3(A0)
  60.             clr.b    4(A0)
  61.             rts
  62.  
  63. ;------------------------------------------------------------------
  64. ; meine eigenen Versionen der C-Standards: fangen NULL-Pointer ab und
  65. ; kopieren maximal 255 Zeichen, beachten NULL_KENNUNG
  66. ;------------------------------------------------------------------
  67.  
  68.             .xref strcpy
  69.             .xref strncpy
  70.             .xref strcat
  71.             .xref strncat
  72.             .xref strlen
  73.  
  74. strcpy:        move.w    #254,D0
  75. strncpy:    move.l    A0,D2
  76.             beq.s    bye_strcpy
  77. entry:        move.l    A1,D1
  78.             beq.s    bye_strcpy
  79.             bra.s    .bloop
  80. .loop:        move.b    (A1)+,(A0)+
  81. .bloop:        dbeq    D0,.loop
  82.             exg        A0,A1
  83.             bsr.s    is0byte__
  84.             exg        A0,A1
  85.             dbne    D0,.loop
  86.             clr.b    (A0)
  87.             move.l    D2,A0
  88. bye_strcpy:    rts
  89.  
  90. strcat:        move.w    #254,D0
  91. strncat:    move.l    A0,D2
  92.             beq.s    bye_strcpy
  93. .loop:        tst.b    (A0)+
  94.             bne.s    .loop
  95.             bsr.s    is0byte__
  96.             beq.s    .loop
  97.             subq.l    #1,A0
  98.             bra.s    entry
  99.  
  100. strlen:        move.l    A0,D0
  101.             beq.s    .bye_strlen
  102.             moveq    #-1,D0
  103. .loop:        tst.b    (A0)+
  104. .bloop:        dbeq    D0,.loop
  105.             bsr.s    is0byte__
  106.             dbne    D0,.loop
  107. .end:        eor.l    #-1,D0
  108. .bye_strlen:rts
  109. ;------------------------------------------------------------------
  110. ;  Zieht eine Linie mit Hilfe des Bresenham-Verfahrens
  111. ;  entnommen aus:
  112. ;  David Kastrup, ''Einfache Kurven auf Rastergrafiken ''
  113. ;  und die Behandlung verschiedener Anstiege implementiert
  114. ;  void line(int x1,int y1,int x2,int y2);
  115. ;------------------------------------------------------------------
  116.  
  117.             .xref line
  118. ;D0.w: x0
  119. ;D1.w: y0
  120. ;D2.w: x1
  121. ;4(sp): y1
  122.  
  123. ;D3: y1
  124. ;D4: a
  125. ;D5: b
  126. ;D6: step
  127. ;D7: inc
  128. ; (sp): x
  129. ; 2(sp): y
  130.  
  131.             regs reg D3-D7/A2    ;6 register
  132. line:        movem.l #regs,-(sp)
  133.             move.w    4+6*4(SP),D3 ; y1
  134.             lea        -4(sp),A1    ; x
  135.             lea        -2(sp),A2    ; y
  136.             move.w    D3,D4
  137.             sub.w    D1,D4    ;a=y1-y0
  138.             move.w    D4,D6
  139.             bpl.s    .get_b
  140.             neg.w    D6        ; abs(a)
  141. .get_b:        move.w    D2,D5
  142.             sub.w    D0,D5    ;b=x1-x0
  143.             move.w    D5,D7
  144.             bpl.s    .chk_a_b
  145.             neg.w    D7        ;abs(b)
  146. .chk_a_b:    cmp.w    D6,D7    ;abs(a)<abs(b)
  147.             bhs.s    .do_compute
  148.             exg        A1,A2    ;xp<->yp
  149.             exg        D0,D1    ;x0<->y0
  150.             exg        D2,D3    ;x1<->y1
  151.             exg        D4,D5    ;a <->b
  152. .do_compute:
  153.             movem.w D0-D1,-(sp) ; x=x0,y=y0
  154.             tst.w    D5        ;b<0
  155.             bpl.s    .init_loop
  156.             neg.w    D5
  157.             neg.w    D4
  158.             move.w    D2,(sp) ;x=x1
  159.             move.w    D3,2(sp);y=y1
  160.             move.w    D0,D2    ;x1=x0
  161. .init_loop: move.w    D5,D6
  162.             lsr.w    #1,D6    ; step=b/2
  163.             sub.w    (SP),D2 ; Anzahl der auszugebenden Punkte
  164.             move.w    D2,D3    ;spart Sichern bei plotpoint-Aufruf
  165.             moveq    #-1,D7    ;inc=-1
  166.             tst.w    D4        ;a>0
  167.             ble.s    .loop
  168.             neg.w    D4        ; a: immer negativ oder 0!
  169.             moveq    #1,D7
  170. .loop:        move.w    (A1),D0
  171.             move.w    (A2),D1
  172.             bsr.s    plotpoint
  173.             addq.w    #1,(SP) ;x++
  174.             add.w    D4,D6    ;step-=a
  175.             bgt.s    .chk_x    ;step<=0
  176.             add.w    D7,2(sp);y+=inc
  177.             add.w    D5,D6    ;step+=b
  178. .chk_x:        dbra    D3,.loop ;x>x1
  179.             addq.l    #4,SP
  180.             movem.l (sp)+,#regs
  181.             rts
  182.  
  183. ;------------------------------------------------------------------
  184. ; Plottet einen Punkt an der angegebenen Koordinate
  185. ; void plotpoint(int x,int y)
  186. ;------------------------------------------------------------------
  187.  
  188.             .xref plotpoint
  189. ;D0.w x
  190. ;D1.w y
  191.  
  192. plotpoint:    cmp.w    #256,D0        ; Über- und Unterlauf abfangen
  193.             bhs.s    .endplot
  194.             cmp.w    #176,D1
  195.             bhs.s    .endplot
  196.             neg.w    D1            ; linke untere Ecke ist 0
  197.             add.w    #175,D1
  198.             lsl.w    #5,D1        ; y in Bytes umrechnen
  199.             move.w    D0,D2        ; x-Wert sichern
  200.             lsr.w    #3,D0        ; Byteoffset in x-Richtung
  201.             add.w    D0,D1        ; gesamter Offset
  202.             and.w    #7,D2        ; PixelOffset im Byte
  203.             eor.w    #7,D2        ; Bitnummer
  204.             lea        screen,A0
  205.             bset    D2,0(A0,D1) ; Punkt setzen
  206.             st        DirtyScreen
  207. .endplot:    rts
  208.  
  209.  
  210. ;------------------------------------------------------------------
  211. ; bewegt die angegebene Anzahl von Bytes von source nach dest
  212. ; void peekpoke(char* source,char* dest);
  213. ;------------------------------------------------------------------
  214.  
  215.             .xref    peekpoke
  216. ; D0.w Anzahl der Bytes
  217. ; A0.l source
  218. ; A0.l destination
  219.  
  220. peekpoke:    move    SR,D1
  221.             or        #%111<<8,SR
  222.             subq.w    #1,D0
  223. .loop:        move.b    (A0)+,(A1)+
  224.             dbra    D0,.loop
  225.             move    D1,SR
  226.             rts
  227.  
  228. GetScreen:    lsl.w    #8,D0
  229.             lea        screen,a0
  230.             lea        (A0,D0.w),A0
  231.             lea        256(a0),a1
  232.             neg.w    D0
  233.             add.w    #21*32*8,D0
  234.             rts
  235.  
  236. GetCharScreen:
  237.             lsl.w    #5,D0
  238.             lea        line00,a0
  239.             lea        (A0,D0.w),A0
  240.             lea        32(a0),a1
  241.             neg.w    D0
  242.             add.w    #32*21,d0
  243.             rts
  244.  
  245.             .xref ScrollUp,ScrollUpR
  246. ScrollUp:    moveq    #0,D0
  247. ScrollUpR:    move.w    D0,-(SP)
  248.             bsr.s    GetScreen
  249.             bsr.s    scr_cpy_up
  250.  
  251.             move.w    (SP)+,D0
  252.             bsr.s    GetCharScreen
  253.             bsr.s    scr_cpy_up
  254.  
  255.             moveq    #21,D0
  256.             bsr        clline
  257.  
  258.             jmp        do_draw(PC)
  259.  
  260. scr_cpy_up:    lsr.w    #2,D0
  261.             bra.s    scr_cpy_ups
  262. scr_cpy_l:    move.l    (A1)+,(A0)+
  263. scr_cpy_ups:dbra    D0,scr_cpy_l
  264.             rts
  265.  
  266.  
  267.             .xref ScrollDown,ScrollDownR
  268. ScrollDown:    moveq    #0,D0
  269. ScrollDownR:move.w    D0,-(SP)
  270.             bsr.s    GetScreen
  271.             bsr.s    scr_cpy_d
  272.  
  273.             move.w    (SP),d0
  274.             bsr.s    GetCharScreen
  275.             bsr.s    scr_cpy_d
  276.  
  277.             move.w    (SP)+,D0
  278.             bsr.s    clline
  279.  
  280.             jmp        do_draw(PC)
  281.  
  282. scr_cpy_d:    lea        (A0,D0.w),A0
  283.             lea        (A1,D0.w),A1
  284.             lsr.w    #2,D0
  285.             bra.s    scr_cpy_ds
  286. scr_cpy_dl:    move.l    -(A0),-(A1)
  287. scr_cpy_ds:    dbra    D0,scr_cpy_dl
  288.             rts
  289.  
  290. ;------------------------------------------------------------------
  291. ;    VOID DrawCursor(WORD x, WORD y)
  292. ;    d0.w -> x
  293. ;    d1.w -> y
  294. ;------------------------------------------------------------------
  295.             .xref DrawCursor
  296. DrawCursor: lea        screen,a0
  297.             lsl.w    #8,d1
  298.             add.w    d1,d0
  299.             lea        (a0,d0.w),a0    ; Adresse des Cursors auf dem Screen
  300.  
  301.             not.b    (a0)
  302.             not.b    32(a0)
  303.             not.b    64(a0)
  304.             not.b    96(a0)            ; Cursor zeichnen/löschen
  305.             not.b    128(a0)
  306.             not.b    160(a0)
  307.             not.b    192(a0)
  308.             not.b    224(a0)
  309.             st        DirtyScreen
  310.  
  311.             rts
  312.  
  313. ;--------------------------------------------------------------------
  314. ;    void cls(void)            : lösche den gesamten screen
  315. ;    void clline(int line)    : lösche eine Zeile
  316. ;    void cllines(int von, int bis) :löschen mehrerer Zeilen
  317. ;    void delxy( int line,int von_x, int bis_x) : löschen in einer Zeile
  318. ;--------------------------------------------------------------------
  319.             .xref cls,clline,cllines,delxy
  320.             clregs reg D3-D5
  321.  
  322. cls:        moveq    #0,D0
  323.             moveq    #21,D1
  324.  
  325. ; D0: Startzeile
  326. ; D1: endzeile
  327. cllines:    movem.l    D3/D4,-(SP)
  328.             move.w    D0,D3
  329.             move.w    D1,D4
  330.             bra.s    .sloop
  331. .loop:        move.w    D3,D0
  332.             bsr.s    clline
  333.             addq.w    #1,D3
  334. .sloop:        cmp.w    D4,D3
  335.             ble.s    .loop
  336.             movem.l    (SP)+,D3/D4
  337.             rts            
  338.  
  339.  
  340. ; d0: Zeile
  341. clline:        moveq    #0,D1
  342.             moveq    #31,D2
  343.  
  344. ; d0: Zeile
  345. ; d1: Start-x
  346. ; d2: End-x
  347. delxy:        movem.l #clregs,-(sp)
  348.             move.w    rev_mode,-(SP)
  349.             clr.b    rev_mode
  350.             move.w    D0,D3
  351.             move.w    D1,D4
  352.             move.w    D2,D5
  353.             bra.s    .sloop
  354. .loop1:        move.w    D4,D0
  355.             move.w    D3,D1
  356.             moveq    #' ',D2
  357.             bsr.s    PutChar
  358.             addq.w    #1,D4
  359. .sloop:        cmp.w    D5,D4
  360.             ble.s    .loop1
  361.             move.w    (SP)+,rev_mode
  362.             movem.l (sp)+,#clregs
  363.             rts
  364.  
  365.  
  366. ;------------------------------------------------------------------
  367. ;    VOID PutChar(WORD x, WORD y, WORD ch);
  368. ;    d0.w -> x
  369. ;    d1.w -> y
  370. ;    d2.w -> Zeichen
  371. ;------------------------------------------------------------------
  372.             .xref PutChar
  373. PutChar:    tst.w    ctrl            ; gleichzeitig check auf
  374.             bne.s    .no_wait            ; ctrl-c und ctrl-q
  375.             movem.w D0-D2,-(SP)
  376.             jsr        WaitBASIC(PC)
  377.             movem.w (SP)+,D0-D2
  378.             bra.s    PutChar
  379.  
  380. .no_wait:    cmp.w    #31,D0
  381.             bhi        .rts
  382.             cmp.w    #21,D1
  383.             bhi.s    .rts
  384.             cmp.w    #255,D2
  385.             bhi.s    .rts
  386.             lea        charscreen,a0    ; Buchstaben merken
  387.             lsl.w    #5,d1            ; 32 Byte pro Zeile
  388.             add.w    d0,d1            ; plus x
  389.             move.b    d2,0(a0,d1.w)    ; und Buchstaben merken
  390.             sub.w    d0,d1            ; x wieder abziehen
  391.  
  392.             lsl.w    #3,d1            ; 32-Byte pro Zeile * 8 Zeilen
  393.             add.w    D1,D0            ; Gesamt-Offset im Screen
  394.  
  395. if EXTRAFONT
  396.             lea        font8x8,a1
  397.             lsl.w    #3,d2
  398.             add.w    D2,A1            ; Adresse des Zeichens im Font
  399.             moveq    #7,D1            ; 8 Pixel hoch
  400. else
  401.             lea        font_d,A0
  402.             tst.l    (A0)
  403.             bne.s    .cont            ;schon initialisiert?
  404.  
  405.             movem.l D0-D2/A0/A2,-(SP) ; initialisieren
  406.             dc.w    $A000            ; LineA-Init
  407.             movem.l (SP)+,D0-D2/A0/A2
  408.             move.l    4(A1),A1
  409.             move.w    $52(A1),D1
  410.             subq.w    #1,D1            ; Höhe des Zeichensatzes
  411.             move.w    D1,font_h-font_d(A0)
  412.             move.w    $50(A1),font_w-font_d(A0) ; Breite des Zeichensatzes
  413.             move.l    $4C(A1),(A0) ; der Zeichensatz selbst
  414.  
  415. .cont:        move.l    (A0),A1
  416.             add.w    D2,A1            ; Adresse des Zeichens im Font
  417.             move.w    font_h-font_d(A0),D1
  418.             move.w    font_w-font_d(A0),D2
  419. endif
  420.  
  421.             lea        screen,a0
  422.             add.w    D0,A0        ; Adresse des Zeichens im Screen
  423.  
  424.             move.b    rev_mode,D0
  425.  
  426. .loop:
  427. if EXTRAFONT
  428.             move.b    (a1)+,(a0)
  429. else
  430.             move.b    (a1),(a0)
  431.             add.w    D2,A1
  432. endif
  433.             eor.b    D0,(a0)            ; Fontdaten kopieren
  434.             lea        32(a0),a0
  435.             dbra    D1,.loop
  436.             st        DirtyScreen
  437. .rts:        rts
  438.  
  439. ;------------------------------------------------------------------
  440.             .data
  441.             .xref cpx_mfdb
  442. cpx_mfdb:    .dc.l    screen
  443.             .dc.w    256
  444.             .dc.w    176
  445.             .dc.w    16
  446.             .dc.w    1
  447.             .dc.w    1
  448.             .dc.w    0,0,0        ; reserviert
  449.  
  450.             .bss
  451.             .xref    charscreen
  452.             .xref    rev_mode
  453.             .xref screen
  454. if !EXTRAFONT
  455. font_h:        ds.w    1
  456. font_w:        ds.w    1
  457. font_d:        ds.l    1
  458. endif
  459.  
  460. rev_mode:    .ds.b    1
  461. .dummy:        .ds.b    1
  462.  
  463. screen:        .ds.b    (256/8)*176 ; Bildschirmspeicher
  464.  
  465. charscreen:
  466. line00:        .ds.b    32            ; Speicher für alle char's
  467. line01:        .ds.b    32
  468. line02:        .ds.b    32
  469. line03:        .ds.b    32
  470. line04:        .ds.b    32
  471. line05:        .ds.b    32
  472. line06:        .ds.b    32
  473. line07:        .ds.b    32
  474. line08:        .ds.b    32
  475. line09:        .ds.b    32
  476. line10:        .ds.b    32
  477. line11:        .ds.b    32
  478. line12:        .ds.b    32
  479. line13:        .ds.b    32
  480. line14:        .ds.b    32
  481. line15:        .ds.b    32
  482. line16:        .ds.b    32
  483. line17:        .ds.b    32
  484. line18:        .ds.b    32
  485. line19:        .ds.b    32
  486. line20:        .ds.b    32
  487. line21:        .ds.b    32
  488.  
  489.  
  490.             .end
  491.