home *** CD-ROM | disk | FTP | other *** search
/ Die ASC Mega 2 / ASC-Mega2-CD-ROM.iso / SPIELE / KAISER / KAISCGA.ASM < prev    next >
Encoding:
Assembly Source File  |  1990-08-17  |  7.9 KB  |  530 lines

  1. ; KAISCGA.ASM
  2. ;
  3. ; cga, CGA Grafik:
  4.  
  5. ; cga, öffentliche Definitionen:
  6.         public    cga_graphmode    ; 17.08.1990
  7.         public    cga_textmode    ; 17.08.1990
  8.         public    cga_horline     ; 17.08.1990
  9.         public    cga_verline     ; 17.08.1990
  10.         public    cga_mal         ; 17.08.1990
  11.         public    cga_char    ; 17.08.1990
  12.         public    cga_text    ; 17.08.1990
  13.         public    cga_row        ; 17.08.1990
  14.         public    cga_kugel    ; 17.08.1990
  15.         public    cga_save    ; 17.08.1990
  16.         public    cga_restore    ; 17.08.1990
  17.  
  18. ; cga, Konstanten:
  19. cga_graph_seg    equ    0B800h    ; Segmente
  20. cga_rowbytes    equ    80    ; Bytes pro Zeile
  21. cga_bankbytes    equ    2000h    ; Bytes pro Bank
  22. cga_bankused    equ    4000    ; benutze Words pro Bank
  23. cga_maxbank    equ    4000h    ; Bytes in allen Banks
  24. cga_graf_zeilen    equ    16    ; Zeilen pro Zeichen im Grafikzeichensatz
  25. cga_text_zeilen    equ    8    ; Zeilen pro Zeichen im Textzeichensatz
  26. cga_text_next    equ    cga_rowbytes*(cga_text_zeilen/(cga_maxbank/cga_bankbytes))-1
  27. cga_graf_next    equ    cga_rowbytes*(cga_graf_zeilen/(cga_maxbank/cga_bankbytes))-2
  28.  
  29. ; cga, lokale Prozeduren:
  30.  
  31. ; cga_calcptr
  32. ;
  33. ; Parameter:    AX: X-Koordinate
  34. ;        BX: Y-Koordinate
  35. ;
  36. ; Rückgabe:    ES:DI: ^ auf Bildschirm
  37. ;
  38. ; verändert:    AX, BX, CX, DX
  39. ;        SI, DI
  40. cga_calcptr    proc near
  41.  
  42.     shr    ax,1            ; DI := X DIV 8
  43.     shr     ax,1
  44.     shr     ax,1
  45.     mov    di,ax
  46.  
  47.     mov    ax,cga_rowbytes        ; + cga_rowbytes * (Y DIV 2)
  48.     mov     cx,bx
  49.     shr     cx,1
  50.     mul    cx
  51.     add    di,ax
  52.  
  53.     and    bx,1
  54.     shl     bx,1
  55.     add     di,cs:[bx+(offset hgc_banks)]
  56.     mov     ax,cga_graph_seg
  57.     mov    es,ax
  58.  
  59.     ret
  60. cga_calcptr    endp
  61.  
  62.  
  63. ; cga_setpixel
  64. ;
  65. ; Parameter:    BX: Y-Koordinate im momentanen Byte (0..7)
  66. ;        ES:DI: ^ auf Bildschirm
  67. ;
  68. ; verändert:    AL
  69. cga_setpixel    proc near
  70.     cmp    farbe,0
  71.     je    cga_sp_1
  72.     mov    al,cs:[bx+(offset hgc_or_tab)]
  73.     or    es:[di],al
  74.     ret
  75. cga_sp_1:
  76.     mov    al,cs:[bx+(offset hgc_and_tab)]
  77.     and    es:[di],al
  78.     ret
  79. cga_setpixel    endp
  80.  
  81. ; cga_nextline
  82. ;
  83. ; Setzt ES:DI auf die nächste Zeile
  84. cga_nextline    proc near
  85.     add    di,cga_bankbytes
  86.         cmp     di,cga_maxbank
  87.     jb      cga_nl_fertig
  88.     sub    di,cga_maxbank-cga_rowbytes
  89. cga_nl_fertig:
  90.     ret
  91. cga_nextline    endp
  92.  
  93. ; cga_setz_graf_z
  94. ;
  95. ; Parameter:    DS:SI: ^ auf Grafikzeichen
  96. ;        ES:DI: ^ auf Bildschirm
  97. cga_setz_graf_z    proc near
  98.     mov    cx,cga_graf_zeilen
  99. cga_sg_loop:
  100.     lodsw
  101.     mov    es:[di],ax
  102.     call    cga_nextline
  103.     loop    cga_sg_loop
  104.  
  105.     ret
  106. cga_setz_graf_z    endp
  107.  
  108. ; cga_xor_graf_z
  109. ;
  110. ; Parameter:    DS:SI: ^ auf Grafikzeichen
  111. ;        ES:DI: ^ auf Bildschirm
  112. cga_xor_graf_z    proc near
  113.     mov    cx,cga_graf_zeilen
  114. cga_xg_loop:
  115.     lodsw
  116.     xor    es:[di],ax
  117.     call    cga_nextline
  118.     loop    cga_xg_loop
  119.  
  120.     ret
  121. cga_xor_graf_z    endp
  122.  
  123. ; cga_setz_text_z
  124. ;
  125. ; Parameter:    DS:SI: ^ auf Textzeichen
  126. ;        ES:DI: ^ auf Bildschirm
  127. ;
  128. ; verändert:    AX,CX,DI
  129. cga_setz_text_z    proc near
  130.     mov    cx,cga_text_zeilen
  131. cga_st_loop:
  132.     lodsb
  133.     mov    es:[di],al
  134.     call    cga_nextline
  135.     loop    cga_st_loop
  136.  
  137.     ret
  138. cga_setz_text_z    endp
  139.  
  140.  
  141. cga_graphmode    proc far
  142.     mov    ax,6
  143.     int    10h
  144.     ret
  145. cga_graphmode    endp
  146.  
  147.  
  148. cga_textmode    proc far
  149.     mov    ax,3
  150.     int    10h
  151.     mov    ah,1
  152.     mov    cx,1000h
  153.     int    10h
  154.     ret
  155. cga_textmode    endp
  156.  
  157.  
  158. cga_horline    proc far
  159. lng        = 6        ; BP + Rücksprung-AD
  160. y        = word ptr [bp+lng]
  161. bis_x        = word ptr [bp+lng+2]
  162. von_x        = word ptr [bp+lng+4]
  163. param_bytes    = 6
  164.     push    bp
  165.     mov    bp,sp
  166.     cld
  167.     inc    bis_x
  168.  
  169.     mov    ax,von_x
  170.     mov    bx,y
  171.     call    cga_calcptr
  172.     xor    dl,dl
  173.     cmp    farbe,0
  174.     je    cga_hl_6
  175.     dec    dl
  176. cga_hl_6:
  177.     mov    bx,von_x
  178.     and    bx,7
  179.     je    cga_hl_1
  180.  
  181. cga_hl_2:
  182.     mov    bx,von_x
  183.     cmp    bx,bis_x
  184.     je    cga_hl_fertig
  185.     and    bx,7
  186.     je    cga_hl_3
  187.     call    cga_setpixel
  188.     inc    von_x
  189.     jmp    short cga_hl_2
  190.  
  191. cga_hl_3:
  192.     inc    di
  193.  
  194. cga_hl_1:
  195.     mov    bx,bis_x
  196.     sub    bx,von_x
  197.     shr     bx,1
  198.         shr     bx,1
  199.         shr     bx,1
  200.     je      cga_hl_4
  201.     mov     cx,bx
  202.     mov     al,dl
  203.     rep     stosb
  204.  
  205. cga_hl_4:
  206.     mov    bx,bis_x
  207.         mov     ax,bx
  208.         and     ax,7
  209.         je      cga_hl_fertig
  210.     and    bx,0FFF8h
  211.     mov    von_x,bx
  212.  
  213. cga_hl_5:
  214.     mov    bx,von_x
  215.     cmp    bx,bis_x
  216.     je    cga_hl_fertig
  217.     and    bx,7
  218.     call    cga_setpixel
  219.     inc    von_x
  220.     jmp    short cga_hl_5
  221.  
  222. cga_hl_fertig:
  223.     pop    bp
  224.     ret    param_bytes
  225. cga_horline    endp
  226.  
  227.  
  228. cga_verline    proc far
  229. lng        = 6        ; BP + Rücksprung-AD
  230. bis_y        = word ptr [bp+lng]
  231. von_y        = word ptr [bp+lng+2]
  232. x        = word ptr [bp+lng+4]
  233. param_bytes    = 6
  234.     push    bp
  235.     mov    bp,sp
  236.     cld
  237.  
  238.     mov    ax,x
  239.     mov    bx,von_y
  240.     call    cga_calcptr
  241.  
  242.     mov    cx,bis_y
  243.     inc    cx
  244.     sub    cx,von_y
  245.     mov    bx,x
  246.     and    bx,7
  247.  
  248. cga_vl_loop:
  249.     call    cga_setpixel
  250.     call    cga_nextline
  251.     loop    cga_vl_loop
  252.  
  253.     pop    bp
  254.     ret    param_bytes
  255. cga_verline    endp
  256.  
  257.  
  258. cga_mal        proc far
  259. lng        = 6        ; BP + Rücksprung-AD
  260. zeichen        = byte ptr [bp+lng]
  261. y        = word ptr [bp+lng+2]
  262. x        = byte ptr [bp+lng+4]
  263. param_bytes    = 6
  264.     push    bp
  265.     mov    bp,sp
  266.     push    ds
  267.     cld
  268.  
  269.     mov    al,x
  270.     xor    ah,ah
  271.     shl    ax,1
  272.     shl    ax,1
  273.     shl    ax,1
  274.     mov    bx,y
  275.     call    cga_calcptr
  276.  
  277.     cmp    xorput,0
  278.     pushf
  279.  
  280.     mov     bh,zeichen
  281.     call    hgc_calc_graf
  282.  
  283.     popf
  284.     jne    cga_mal_1
  285.     call    cga_setz_graf_z
  286.     jmp    short    cga_mal_2
  287. cga_mal_1:
  288.     call    cga_xor_graf_z
  289. cga_mal_2:
  290.  
  291.     pop    ds
  292.     pop     bp
  293.     ret    param_bytes
  294. cga_mal        endp
  295.  
  296.  
  297. cga_char    proc far
  298. lng        = 6        ; BP + Rücksprung-AD
  299. zeichen        = byte ptr [bp+lng]
  300. y        = word ptr [bp+lng+2]
  301. x        = byte ptr [bp+lng+4]
  302. param_bytes    = 6
  303.     push    bp
  304.     mov    bp,sp
  305.     push    ds
  306.     cld
  307.  
  308.     mov    al,x
  309.     xor    ah,ah
  310.     shl    ax,1
  311.     shl    ax,1
  312.     shl    ax,1
  313.     mov    bx,y
  314.     call    cga_calcptr
  315.  
  316.     mov     al,zeichen
  317.     call    hgc_calc_text
  318.  
  319.     call    cga_setz_text_z
  320.  
  321.     pop    ds
  322.     pop     bp
  323.     ret    param_bytes
  324. cga_char    endp
  325.  
  326.  
  327.  
  328. cga_text    proc far
  329. lng        = 6        ; BP + Rücksprung-AD
  330. text        = [bp+lng]
  331. y        = word ptr [bp+lng+4]
  332. x        = byte ptr [bp+lng+6]
  333. param_bytes    = 8
  334.  
  335. cga_tx_repl    macro    zahl1,zahl2
  336.     local    cga_tx_repl_1
  337.     cmp    al,zahl1
  338.     jne    cga_tx_repl_1
  339.     mov    al,zahl2
  340.     jmp    short cga_tx_do
  341. cga_tx_repl_1:
  342.                   endm
  343.  
  344.     push    bp
  345.     mov    bp,sp
  346.     push    ds
  347.     cld
  348.  
  349.     mov    al,x
  350.     xor    ah,ah
  351.     shl    ax,1
  352.     shl    ax,1
  353.     shl    ax,1
  354.     mov    bx,y
  355.     call    cga_calcptr
  356.  
  357.     mov    dx,ds
  358.     lds    si,text
  359.     lodsb
  360.     mov    cl,al
  361.     xor    ch,ch
  362. cga_tx_loop:
  363.     lodsb
  364.     push    cx
  365.     push    si
  366.     push    ds
  367.     cmp    al,129
  368.     jb    cga_tx_do
  369.     cga_tx_repl    142,64        ; Ä
  370.     cga_tx_repl    153,96        ; Ö
  371.     cga_tx_repl    154,123        ; Ü
  372.     cga_tx_repl    132,124        ; ä
  373.     cga_tx_repl    148,125        ; ö
  374.     cga_tx_repl    129,126        ; ü
  375.     cga_tx_repl    225,127        ; ß
  376. cga_tx_do:
  377.     sub    al,20h
  378.     mov    ds,dx
  379.     call    hgc_calc_text
  380.     call    cga_setz_text_z
  381.     sub    di,cga_text_next
  382.     pop    ds
  383.     pop    si
  384.     pop    cx
  385.     loop    cga_tx_loop
  386.  
  387.     pop    ds
  388.     pop     bp
  389.     ret    param_bytes
  390. cga_text    endp
  391.  
  392.  
  393. cga_row        proc far
  394. lng        = 6    ; BP + Rücksprung-AD
  395. y        = byte ptr ss:[bp+lng]
  396. param_bytes    = 2
  397.  
  398.     push    bp
  399.     mov    bp,sp
  400.     push    ds
  401.     cld
  402.  
  403.     mov    al,y
  404.     add    al,feld_oben
  405.     xor    ah,ah
  406.     mov    cl,40
  407.     mul    cl
  408.     add    ax,offset spielfeld
  409.     mov    si,ax
  410.  
  411.     mov     ax,feld_x
  412.     mov    bx,c_y
  413.     call    cga_calcptr
  414.  
  415.     mov    cx,40
  416.  
  417. cga_row_loop:
  418.     push    cx
  419.  
  420.     lodsb
  421.     push    ds
  422.     push    si
  423.     mov    bh,al
  424.     call    hgc_calc_graf
  425.     call    cga_setz_graf_z
  426.     sub    di,cga_graf_next
  427.     pop    si
  428.     pop    ds
  429.     pop    cx
  430.     loop    cga_row_loop
  431.  
  432.     pop    ds
  433.     pop    bp
  434.     ret    param_bytes
  435. cga_row        endp
  436.  
  437.  
  438. cga_kugel    proc far
  439. lng        = 6    ; BP + Rücksprung-AD
  440. y        = word ptr ss:[bp+lng]
  441. x        = word ptr ss:[bp+lng+2]
  442. param_bytes    = 4
  443.     push    bp
  444.     mov    bp,sp
  445.     push    ds
  446.     cld
  447.  
  448.     mov    ax,x
  449.     mov    bx,y
  450.     call    cga_calcptr
  451.  
  452.     push    cs
  453.     pop    ds
  454.     mov    si,offset hgc_kugel_data
  455.  
  456.     mov    cx,4
  457.     xor    bx,bx
  458.  
  459. cga_ku_loop:
  460.     push    cx
  461.     lodsw
  462.     mov    cx,x
  463.     and    cx,7
  464.     shr    ax,cl
  465.         xchg    al,ah
  466.     xor    es:[di],ax
  467.     call    cga_nextline
  468.  
  469.     pop    cx
  470.     loop    cga_ku_loop
  471.  
  472.     pop    ds
  473.     pop    bp
  474.     ret    param_bytes
  475. cga_kugel    endp
  476.  
  477.  
  478. cga_save    proc far
  479. lng        = 6    ; BP + Rücksprung-AD
  480. buffer        = ss:[bp+lng]
  481. param_bytes    = 4
  482.  
  483.     push    bp
  484.     mov    bp,sp
  485.     push    ds
  486.  
  487.     les    di,buffer
  488.     mov    bx,cga_graph_seg
  489.     mov    ds,bx
  490.     xor    si,si
  491.     mov    cx,cga_bankused
  492.     rep    movsw
  493.     add    bx,(cga_bankbytes/10h)
  494.     mov    ds,bx
  495.     xor    si,si
  496.     mov    cx,cga_bankused
  497.     rep    movsw
  498.  
  499.     pop    ds
  500.     pop    bp
  501.     ret    param_bytes
  502. cga_save    endp
  503.  
  504.  
  505. cga_restore    proc far
  506. lng        = 6    ; BP + Rücksprung-AD
  507. buffer        = ss:[bp+lng]
  508. param_bytes    = 4
  509.  
  510.     push    bp
  511.     mov    bp,sp
  512.     push    ds
  513.  
  514.     lds    si,buffer
  515.     mov    bx,cga_graph_seg
  516.     mov    es,bx
  517.     xor    di,di
  518.     mov    cx,cga_bankused
  519.     rep    movsw
  520.     add    bx,(cga_bankbytes/10h)
  521.     mov    es,bx
  522.     xor    di,di
  523.     mov    cx,cga_bankused
  524.     rep    movsw
  525.  
  526.     pop    ds
  527.     pop    bp
  528.     ret    param_bytes
  529. cga_restore    endp
  530.