?login_element?

Subversion Repositories NedoOS

Rev

Rev 1605 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. COLOR=0
  2.     module TextMode
  3. PORT_SELECT = #7c3b
  4. init:
  5.     ld hl, font_file, b, Dos.FMODE_READ
  6.     call Dos.fopen
  7.     push af
  8.     ld bc, 2048, hl, font
  9.     call Dos.fread
  10.     pop af
  11.     call Dos.fclose
  12.    
  13.     IFDEF UNO
  14.     ;; Force turbo mode
  15.     ld bc, 64571 : ld a, #0b : out (c), a
  16.     ld bc, 64827 : in a, (c) : or #c0 : out (c),a
  17.     ENDIF
  18. cls:
  19.     ld a, 7 : call Memory.setPage
  20.  
  21.     IFDEF UNO
  22.     ld a, #3E : out (#ff), a
  23.     ELSE
  24.     ld  bc, #EFF7   ;   Scorpio
  25.     ld a,2
  26.     out (C), a
  27.     ENDIF
  28.  
  29.     di
  30.     ld  hl,0, d,h, e,h, b,h, c,b
  31.     add hl,sp
  32.     ld  sp,#c000 + 6144
  33. .loop
  34.     dup 12
  35.         push    de
  36.     edup
  37.  
  38.     djnz        .loop
  39.  
  40.     ld  b,c
  41.     ld  sp,#e000 + 6144
  42. .loop2:
  43.     dup 12
  44.         push    de
  45.     edup
  46.  
  47.     djnz .loop2
  48.     ld  sp,hl
  49.     ld hl ,0 : ld (coords), hl
  50.     xor a : call Memory.setPage
  51.    
  52.     ei
  53.     ret
  54.  
  55. ; A - line
  56. usualLine:
  57.    ld d, a
  58.    jr fill
  59. ; A - line
  60. highlightLine:
  61.     ld d, a
  62. fill:
  63.     ld e, 0, b, 64
  64. .lloop
  65.         push bc
  66.         push de
  67.         call findAddr
  68.     ld a, 7 : call Memory.setPage
  69.        
  70.         ld b, 8
  71. .cloop 
  72.         ld a, (de) : xor #ff : ld (de), a
  73.         inc d
  74.         djnz .cloop
  75.         pop de
  76.         inc e
  77.         pop bc
  78.         djnz .lloop
  79.  
  80.     xor a : call Memory.setPage
  81.     ret
  82.  
  83. printZ:
  84.     ld a, (hl) : and a : ret z
  85.     push hl
  86.     call putC
  87.     pop hl
  88.     inc hl
  89.     jr printZ
  90.  
  91.  
  92. ; A - char
  93. putC:
  94.     ld (drawC.char_tmp), a
  95.  
  96.         cp 13
  97.         jp z, .cr
  98.    
  99.     ld de, (coords)
  100.     ld a, e
  101.     cp 85
  102.     ret nc
  103.  
  104.  
  105.     ld a, 7
  106.     call Memory.setPage
  107.     push iy
  108.     call drawC
  109.     pop iy
  110.  
  111.     ld hl, coords
  112.     inc (hl)
  113.  
  114.     jr .exit
  115. .cr
  116.         ld hl, (coords)
  117.         inc h
  118.         ld l, 0, (coords), hl
  119.         cp 24
  120.         ret c
  121.         ld hl, 0, (coords), hl
  122. .exit
  123.     xor a : call Memory.setPage
  124.         ret    
  125.  
  126. drawC:
  127.     ld hl, (coords)
  128.     ld b, l
  129.     call .calc
  130.     ld d, h
  131.     ld e, l
  132.     ld (.rot_tmp), a
  133.     call findAddr
  134.     push de
  135.     call .get_char
  136.  
  137.     pop hl
  138. .print0
  139.     ld ix, hl
  140.     ld a, h
  141.     bit 5, a
  142.     jr z, .ok
  143.     inc l
  144. .ok
  145.     xor #20 : ld h, a
  146.     ld iy, hl
  147.     ld a, (.rot_tmp)
  148.     call .rotate_mask
  149.     ld a, (.rot_tmp)
  150.     jp basic_draw
  151. .calc
  152.       ld l,0
  153.       ld a, b : and a : ret z
  154.       ld ix, 0
  155.       ld de,6
  156. 1     add ix, de
  157.       djnz 1b
  158.       ld de, -8
  159. 2     ld a, ixh
  160.       and a
  161.       jr nz, 3f
  162.       ld a, ixl
  163.       cp 8
  164.       ret c
  165. 3    
  166.       add ix, de
  167.       inc l
  168.       jr 2b
  169.       ret
  170.  
  171. .rotate_mask
  172.     ld hl, #03ff
  173.     and a : ret z
  174. .rot_loop
  175.     ex af, af
  176.     ld a,l
  177.     rrca
  178.     rr h
  179.     rr l
  180.     ex af, af
  181.     dec a
  182.     jr nz, .rot_loop
  183.     ret
  184. .get_char:
  185.     ld a, (.char_tmp)
  186.     ld l, a
  187.     ld h, 0
  188.     add hl, hl
  189.     add hl, hl
  190.     add hl, hl
  191.     ld bc, font
  192.     add hl, bc
  193.     ex hl, de
  194.     ret
  195. .char_tmp db 0
  196. .rot_tmp  db 0
  197. ; A - rotation counter
  198. ; DE - font PTR
  199. ; HL - mask
  200. ; IX - left half on screen
  201. ; IY - right half on screen
  202. basic_draw:
  203.     ld (.rot_cnt),a
  204.  
  205.     ld a, l
  206.     ld (.mask1), a
  207.     ld a, h
  208.     ld (.mask2), a
  209.     ld b, 8
  210. .printIt
  211.     ld a, (de)
  212.     ld h, a
  213.     ld l, 0
  214.     ld a, 0
  215. .rot_cnt = $ - 1
  216.     and a : jr z, .skiprot
  217. .rot
  218.     ex af, af
  219.     ld a,l
  220.     rrca
  221.     rr h
  222.     rr l
  223.     ex af, af
  224.     dec a
  225.     jr nz, .rot
  226. .skiprot
  227.     ld a, (iy)
  228.     and #0f
  229. .mask1 = $ - 1
  230.     or l
  231.     ld (iy), a
  232.     ld a, (ix)
  233.     and #fc
  234. .mask2 = $ -1
  235.     or h
  236.     ld (ix), a
  237.     inc ixh
  238.     inc iyh
  239.     inc de
  240.     djnz .printIt
  241.     ret
  242.  
  243.  
  244. ; H - line
  245. ; A - char
  246. fillLine:
  247.     ld d, h, e, 0 : call gotoXY
  248.     ld b, 85
  249. .loop
  250.     push af, bc
  251.     call putC
  252.     pop bc, af
  253.     djnz .loop
  254.     ret
  255.  
  256.  
  257. gotoXY:
  258.     ld (coords), de
  259.     ret
  260.  
  261. ; D - Y
  262. ; E - X
  263. ; OUT: de - coords
  264. findAddr:
  265.     ld a, e
  266.     srl a
  267.     ld e,a
  268.     ld b, #E0
  269.     jr c, .proc
  270.     ld b, #C0
  271. .proc
  272.     LD A,D
  273.     AND 7
  274.     RRCA
  275.     RRCA
  276.     RRCA
  277.     OR E
  278.     LD E,A
  279.     LD A,D
  280.     AND 24
  281.     OR b
  282.     LD D,A
  283.     ret
  284.  
  285. toggleColor:
  286.     ld a,(curState)
  287.     cp 7
  288.     jp z, sevenEleven
  289. ;zerroTolerance
  290.     ld a,7
  291.     ld (curState),a
  292.     out (#fe),a
  293.     ret
  294. sevenEleven:
  295.     ld a,0
  296.     ld (curState),a
  297.     out (#fe),a
  298.     ret
  299. curState:
  300.     db 0
  301. disable:
  302.     IFDEF UNO
  303.     xor a : out (#fe), a : out (#ff), a
  304.     ELSE
  305.     ld  bc, #EFF7   ;   Scorpio
  306.     ld a,0
  307.     out (C), a
  308.     ENDIF
  309.     ret
  310.  
  311. coords dw 0
  312. font equ #4000 ; Using ZX-Spectrum screen as font buffer
  313. font_file db "font80.bin", 0
  314.     endmodule
  315.  
  316. exit:
  317.     ld bc, TextMode.PORT_SELECT, a, 1          
  318.     out (c), a
  319.     inc b : xor a
  320.     out (c), a
  321.     rst 0