BEDEDIT.ASM

Assembly source for Bedlam, 6419 lines. Raw file

;  BEDLAM v0.7
;  <c> LKS 1995.
;  Create: 18\Jun\1995

;  I'm well aware that I don't have a book named after me.
; (Fat and Frantic - Hier soir, ma femme vacuumait ma tete)

;  Password for this ZIP is ABBIE.


.MODEL large

.STACK 8192

.DATA

.CODE
.386

JUMPS

  ;  Segment storage.

_zero_seg	dw 0000h
_psp_seg	dw 0000h
_code_seg	dw 0000h
_data_seg	dw 0000h
_stack_seg	dw 0000h

_alloc_seg	dw 0000h	;  192k allocated (split into 3 x 64k)
_scr_seg	dw 0000h
_sprite_seg	dw 0000h
_level_seg	dw 0000h
_intro_seg	dw 0000h

_text_seg	dw 0B800h
_graph_seg	dw 0A000h

  ;  Memory allocation.

_code_size	dw 0000h	;  Size of shrunk CS.
_free_size	dw 0000h	;  Free memory after shrink.

  ;  Interrupt vectors.

_int1C_off	dw 0000h	;  Old timer interrupt.
_int1C_seg	dw 0000h
_int09_off	dw 0000h	;  Old keyboard interrupt.
_int09_seg	dw 0000h

  ;  File handling.

_fname		db 'BEDLAM.BED  ', 00h
_handle		dw 0000h

  ;  Misc.

_random		dw 4 dup (0000h)

_editflag	dw -1
_devflag	dw -1



.STARTUP

start:
  mov _psp_seg, es
  mov _code_seg, cs
  mov _data_seg, ds
  mov _stack_seg, ss

  call logon
  call main
  call logoff
.EXIT



;---- LOGON -------------------------------------------------------------------;


;---- Logon.

logon:

    ;  80x50 text mode.

  mov ax, 3
  int 10h
  mov ax, 1112h
  xor bx, bx
  int 10h

    ;  Print logon message.

  mov es, _text_seg
  xor di, di
  call printc
  db 255, 19h, ' þ ', 255, 1Fh, 'Bedlam v0.7 + Editor', 255, 19h, ' þ ', 255, 1Fh, '<c> LKS 1995', 255, 19h, ' þ ', 255, 1Eh, 'Setting up resources..              ', 255, 19h, ' þ ', 00h
  call print
  db 0Dh, 0Ah, 0Ah, 00h

    ;  Parse parameters.

;  call param

    ;  If in edit mode, check mouse driver loaded.

  cmp _editflag, 0
  je logon_noedit

  call print
  db 'þ Initializing mouse driver.', 0Dh, 0Ah, 0Ah, 00h

  xor ax, ax
  int 33h
  cmp ax, -1
  je logon_noedit

    ;  Error with mouse.
  call print
  db 'ERROR - Cannot find Microsoft compatible mouse driver.', 0Dh, 0Ah, 00h
.EXIT

logon_noedit:

    ;  Shrink memory.

  call print
  db 'þ Setting up memory', 0Dh, 0Ah, 0Ah
  db '  Shrinking CS:', 0Dh, 0Ah
  db '    CS = ', 00h
  mov cx, 1004h
  mov dx, cs
  call printnum
  call print
  db 'h', 0Dh, 0Ah, '    Size = ', 00h

  mov bx, _stack_seg
  sub bx, _psp_seg
  mov ax, sp
  add ax, 15
  shr ax, 4
  add bx, ax
  mov cx, 1004h
  mov _code_size, bx
  mov dx, bx
  call printnum
  call print
  db 'h', 0Dh, 0Ah, 0Ah, 00h
  mov ah, 4Ah
  mov es, _psp_seg
  int 21h

  jnc logon_csok
  call print
  db 0Dh, 0Ah, 'þ ERROR - Cannot shrink CS.', 0Dh, 0Ah, 00h
.EXIT
logon_csok:

  call print
  db '  Allocating buffers:', 0Dh, 0Ah
  db '    FreeMem = ', 00h

  mov ah, 48h
  mov bx, 0FFFFh
  int 21h
  mov _free_size, bx
  mov cx, 1004h
  mov dx, _free_size
  call printnum
  call print
  db 'h', 0Dh, 0Ah, 00h

  cmp _free_size, 3283h
  jae logon_freememok
  call print
  db 0Dh, 0Ah, 'þ ERROR - Cannot allocate 202k buffers.', 0Dh, 0Ah, 00h
.EXIT
logon_freememok:

    ;  Allocate buffers.

  mov ah, 48h
  mov bx, 3280h
  int 21h
  mov _alloc_seg, ax
  mov _scr_seg, ax
  add ax, 1000h
  mov _sprite_seg, ax
  add ax, 1000h
  mov _level_seg, ax
  add ax, 1000h
  mov _intro_seg, ax

  call print
  db '    ScreenBuf = ', 00h
  mov cx, 1004h
  mov dx, _scr_seg
  call printnum
  call print
  db 'h', 0Dh, 0Ah, '    SpriteSeg = ', 00h
  mov dx, _sprite_seg
  call printnum
  call print
  db 'h', 0Dh, 0Ah, '    LevelSeg = ', 00h
  mov dx, _level_seg
  call printnum
  call print
  db 'h', 0Dh, 0Ah, '    IntroSeg = ', 00h
  mov dx, _intro_seg
  call printnum
  call print
  db 'h', 0Dh, 0Ah, 0Ah, 00h

    ;  Load data file.

  call print
  db 'þ Loading BEDLAM.BED', 0Dh, 0Ah, 0Ah, 00h

    ;  Open file.

  mov ax, 3D00h
  mov dx, offset _fname
  mov ds, _code_seg
  int 21h
  jnc logon_fileok
  call print
  db 'þ ERROR - Cannot find default data file.', 0Dh, 0Ah
  db '          make sure it is in current directory.', 0Dh, 0Ah, 00h
.EXIT
logon_fileok:

  mov _handle, ax

    ;  Read palette.

  mov ah, 3Fh
  mov bx, _handle
  mov cx, 768
  mov dx, offset _game_pal
  mov ds, _code_seg
  int 21h
  jc logon_read1err
  cmp ax, 768
  jne logon_read1err

    ;  Read sprites.

  mov ah, 3Fh
  mov bx, _handle
  mov cx, 8000h
  xor dx, dx
  mov ds, _sprite_seg
  int 21h
  jc logon_read1err
  cmp ax, 8000h
  je logon_read1ok
logon_read1err:
  call print
  db 'þ ERROR - Cannot read the sprite data in this file.', 0Dh, 0Ah, 00h
.EXIT
logon_read1ok:

    ;  Read levels.

  mov ah, 3Fh
  mov bx, _handle
  mov cx, 8000h
  xor dx, dx
  mov ds, _level_seg
  int 21h
  jc logon_read2err
  cmp ax, 8000h
  jne logon_read2err
  mov ah, 3Fh
  mov bx, _handle
  mov cx, 8000h
  mov dx, 8000h
  mov ds, _level_seg
  int 21h
  jc logon_read2err
  cmp ax, 8000h
  je logon_read2ok
logon_read2err:
  call print
  db 'þ ERROR - Cannot read the level data in this file.', 0Dh, 0Ah, 00h
.EXIT
logon_read2ok:

    ;  Close file

  mov ah, 3Eh
  mov bx, _handle
  int 21h

    ;  Set up interrupt hooks.

  call print
  db 'þ Hooking interrupts', 0Dh, 0Ah, 0Ah, 00h

  mov ax, 351Ch
  int 21h
  mov _int1C_off, bx
  mov _int1C_seg, es

  mov ax, 3509h
  int 21h
  mov _int09_off, bx
  mov _int09_seg, es

  call print
  db '  INT 1Ch - System timer IRQ:  OldVect = ', 00h
  mov cx, 1004h
  mov dx, _int1C_seg
  call printnum
  call print
  db 'h:', 00h
  mov dx, _int1C_off
  call printnum
  call print
  db 'h', 0Dh, 0Ah
  db '                               NewVect = ', 00h
  mov dx, cs
  call printnum
  call print
  db 'h:', 00h
  mov dx, offset cs: timer
  call printnum
  call print
  db 'h', 0Dh, 0Ah, 0Ah, 00h

  call print
  db '  INT 09h - Keyboard IRQ:  OldVect = ', 00h
  mov cx, 1004h
  mov dx, _int09_seg
  call printnum
  call print
  db 'h:', 00h
  mov dx, _int09_off
  call printnum
  call print
  db 'h', 0Dh, 0Ah
  db '                           NewVect = ', 00h
  mov dx, cs
  call printnum
  call print
  db 'h:', 00h
  mov dx, offset cs: kbd
  call printnum
  call print
  db 'h', 0Dh, 0Ah, 00h

    ;  Pause for keypress.

  call print
  db 0Ah, 'þ Press a key..', 00h
  mov ah, 7
  int 21h
  cmp al, 27
  jne logon_notesc
  call logoff
.EXIT
logon_notesc:

  mov ax, 251Ch
  mov dx, offset cs: timer
  mov ds, _code_seg
  int 21h

  mov ax, 2509h
  mov dx, offset cs: kbd
  mov ds, _code_seg
  int 21h

    ;  Graphics mode.

  mov ax, 13h
  int 10h

    ;  Set palette.

  mov ax, 1012h
  xor bx, bx
  mov cx, 256
  mov dx, offset cs: _game_pal
  mov es, _code_seg
  int 10h

    ;  Clear screen buffer.

  mov es, _scr_seg
  xor edi, edi
  mov ecx, 16000
  xor eax, eax
  rep stosd

    ;  Level parameter.

  mov es, _psp_seg
  cmp byte ptr es: [80h], 2
  jb logon_noparam
  mov al, es: [82h]
  sub al, 'A'
  and al, 15
  mov cs: _levelno, al
logon_noparam:

    ;  Level data.

  mov bl, cs: _levelno
  xor bh, bh
  mov al, cs: _level_startx_[bx]
  mov cs: _level_startx[bx], al
  mov al, cs: _level_starty_[bx]
  mov cs: _level_starty, al
  mov al, cs: _level_width_[bx]
  mov cs: _level_width, al
  mov al, cs: _level_height_[bx]
  mov cs: _level_height, al
  mov al, cs: _level_time_[bx]
  mov cs: _level_time, al
  mov al, cs: _level_dias_[bx]
  mov cs: _level_dias, al
  mov al, cs: _level_points_[bx]
  mov cs: _level_points, al

  ret



;---- LOGOFF ------------------------------------------------------------------;


;---- Logoff.

logoff:
    ;  Free memory
  mov ah, 49h
  mov es, _alloc_seg
  int 21h

    ;  Unhook interrupts.

  mov ax, 251Ch
  mov dx, _int1C_off
  mov ds, _int1C_seg
  int 21h

  mov ax, 2509h
  mov dx, _int09_off
  mov ds, _int09_seg
  int 21h

    ;  Clear screen.
  mov ax, 3
  int 10h
  mov ax, 1112h
  xor bx, bx
  int 10h

  ret



;---- INTERRUPT HANDLERS ------------------------------------------------------;


;---- Int 1Ch

_timer_in	db 00h

_timer_proc	dw offset cs: timer_null	;  Address of timer procedure.

timer:
  cmp _timer_in, 0
  jne timer_end

  mov _timer_in, 1
  push bx

  mov bx, _timer_proc
  sub cs: _random, bx
  rol cs: _random, 3
  cmp word ptr cs: [bx], 9090h
  jne timer_noproc

  call bx

timer_noproc:
  pop bx

    ;  Randomize.

  push bx
  add cs: _random[0], 128Ah
  sbb cs: _random[2], 8B12h
  xor cs: _random[4], 2761h
  adc cs: _random[6], 72F7h
  mov bx, cs: _random[0]
  xor cs: _random[1], bx
  sbb cs: _random[3], bx
  xor cs: _random[5], bx
  rol cs: _random[6], 1
  add bx, cs: _random[6]
  adc bx, 3897h
  add cs: _random[4], bx
  xor bx, cs: _random[4]
  sbb bx, 9781h
  add cs: _random[2], bx
  ror dword ptr cs: _random[1], 3
  xor bx, cs: _random[1]
  add bx, cs: _random[5]
  sbb cs: _random[0], bx
  pop bx

  mov _timer_in, 0

timer_end:
  push _int1C_seg
  push _int1C_off
  retf

  ;  Null timer proc.
timer_null:
  nop
  nop
  ret



;---- Int 09h

;  Keyboard IRQ.

_kbd_keys	db 80h dup (00h)

_KBD_ESC	equ _kbd_keys[01h]
_KBD_UP		equ _kbd_keys[48h]
_KBD_DOWN	equ _kbd_keys[50h]
_KBD_LEFT	equ _kbd_keys[4Bh]
_KBD_RIGHT	equ _kbd_keys[4Dh]
_KBD_FIRE	equ _kbd_keys[1Dh]
_KBD_RSHIFT	equ _kbd_keys[36h]
_KBD_SPACE	equ _kbd_keys[39h]


newint09:

kbd:

  push ax
  push bx

    ;  Store keypress or keyrelease.

  in al, 60h
  xor bh, bh
  mov bl, al
  test al, 80h
  jz kbd_press

    ;  Key released.
  and bl, 7Fh
  mov _kbd_keys[bx], 0
  jmp kbd_after

kbd_press:

    ;  Key pressed.
  mov _kbd_keys[bx], -1

kbd_after:

  add cs: _random[1], ax
  sbb cs: _random[3], ax

  pop bx
  pop ax

  cli
  push ax
  mov al, 20h
  out 20h, al
  pop ax
  iret



;---- MAIN --------------------------------------------------------------------;


;---- Main.

main:

  cmp _editflag, 0
  je main_noteditor
  call edit
  jmp main_end
main_noteditor:

main_loop:

  call intro
  cmp ax, -1
  je main_end

  call game
  jmp main_loop

main_end:

  ret



;---- EDIT --------------------------------------------------------------------;

;  Bedlam Editor GUI.

  ;  Mouse info.

_mouse_b	dw 0000h
_mouse_x	dw 0000h
_mouse_y	dw 0000h
_mouse_xold	dw 0000h
_mouse_yold	dw 0000h

  ;  Window structures.

_worder		dw 32, 0, 64

_window_x1:
_charwin_x1	dw 10
_window_y1:
_charwin_y1	dw 13
_window_x2:
_charwin_x2	dw 277
_window_y2:
_charwin_y2	dw 162
_window_off1:
_charwin_off1	dw 10+13*320
_window_off2:
_charwin_off2	dw 277+162*320
_window_w:
_charwin_w	dw 268
_window_h:
_charwin_h	dw 150
_window_proc:
_charwin_proc	dw offset cs: charwin_proc
_window_len:
_charwin_len	db 10
_window_title:
_charwin_title	db 'CHARACTERS...'

_mapwin_x1	dw 20
_mapwin_y1	dw 26
_mapwin_x2	dw 287
_mapwin_y2	dw 183
_mapwin_off1	dw 20+26*320
_mapwin_off2	dw 287+183*320
_mapwin_w	dw 268
_mapwin_h	dw 158
_mapwin_proc	dw offset cs: mapwin_proc
_mapwin_len	db 3
_mapwin_title	db 'MAP..........'

_editwin_x1	dw 0
_editwin_y1	dw 0
_editwin_x2	dw 214
_editwin_y2	dw 177
_editwin_off1	dw 0+0*320
_editwin_off2	dw 214+177*320
_editwin_w	dw 215
_editwin_h	dw 178
_editwin_proc	dw offset cs: editwin_proc
_editwin_len	db 3
_editwin_title	db 'SPRITE EDITOR'



;---- Edit.

edit:
  call edit_logon
  call edit_main
  call edit_logoff
  ret



;---- Edit_Logon.

edit_logon:

    ;  Copy level into buffer.

  push es
  push ds
  push ax
  push ecx
  push esi
  push edi
  cld
  mov ds, _level_seg
  mov es, _code_seg
  xor esi, esi
  xor edi, edi
  xor al, al
  mov ah, cs: _levelno
  shl ah, 4
  mov si, ax
  mov di, offset _level
  xor ecx, ecx
  mov cx, 64*64/4
  rep movsd
  pop edi
  pop esi
  pop ecx
  pop ax
  pop ds
  pop es

    ;  Create background bitmap.

  mov es, _intro_seg
  xor si, si
  xor edi, edi
  mov di, 2

  mov dx, 100
edit_logon_yloop:

  mov cx, 25
edit_logon_xloop:
  mov ah, cs: _intro_back[si]
  mov al, ah
  and al, 3
  ror ah, 2
  mov es: [di], al
  mov al, ah
  and al, 3
  ror ah, 2
  mov es: [di+1], al
  mov al, ah
  and al, 3
  ror ah, 2
  mov es: [di+2], al
  mov al, ah
  and al, 3
  ror ah, 2
  mov es: [di+3], al
  add dword ptr es: [di], 19191919h
  inc si
  add di, 4
  loop edit_logon_xloop

  add di, 2
  dec dx
  jnz edit_logon_yloop

    ;  Limit mouse.

  call mouse_limitscreen

  ret



;---- Edit_Logoff.

edit_logoff:
  ret



;---- Edit_Main.

edit_main:

    ;  Draw screen.

  mov es, _scr_seg

  call edit_redraw
  call mouse_get
  call mouse_draw
  call update

    ;  Wait for mouse event.

edit_main_loop:

  call edit_redraw

  call mouse_get

  test _mouse_b, 1
  jnz edit_main_lbutton
  test _mouse_b, 2
  jnz edit_main_rbutton

  call mouse_draw

  call update

  cmp _KBD_ESC, 0
  je edit_main_loop

  ret



  ;  Left mouse button event.

edit_main_lbutton:
  push ax
  push cx
  push dx
  push bx

    ;  Check which window the mouse is in.

  mov ax, 10h
  mov cx, _mouse_x
  mov dx, _mouse_y

    ;  Test top window first.

  mov bx, _worder[0]
  cmp cx, word ptr _window_x1[bx]
  jb edit_main_lbutton_notwin1
  cmp cx, word ptr _window_x2[bx]
  ja edit_main_lbutton_notwin1
  cmp dx, word ptr _window_y1[bx]
  jb edit_main_lbutton_notwin1
  cmp dx, word ptr _window_y2[bx]
  ja edit_main_lbutton_notwin1

  sub cx, word ptr _window_x1[bx]
  sub dx, word ptr _window_y1[bx]
  mov bx, word ptr _window_proc[bx]
  cmp word ptr cs: [bx], 9090h
  jne edit_main_lbutton_error
  call bx
  jmp edit_main_lbutton_end

edit_main_lbutton_notwin1:

    ;  Test middle window.

  mov bx, _worder[2]
  cmp cx, word ptr _window_x1[bx]
  jb edit_main_lbutton_notwin2
  cmp cx, word ptr _window_x2[bx]
  ja edit_main_lbutton_notwin2
  cmp dx, word ptr _window_y1[bx]
  jb edit_main_lbutton_notwin2
  cmp dx, word ptr _window_y2[bx]
  ja edit_main_lbutton_notwin2

  sub cx, word ptr _window_x1[bx]
  sub dx, word ptr _window_y1[bx]
  mov bx, word ptr _window_proc[bx]
  cmp word ptr cs: [bx], 9090h
  jne edit_main_lbutton_error
  call bx
  jmp edit_main_lbutton_end

edit_main_lbutton_notwin2:

    ;  Test bottom window.

  mov bx, _worder[4]
  cmp cx, word ptr _window_x1[bx]
  jb edit_main_lbutton_notwin3
  cmp cx, word ptr _window_x2[bx]
  ja edit_main_lbutton_notwin3
  cmp dx, word ptr _window_y1[bx]
  jb edit_main_lbutton_notwin3
  cmp dx, word ptr _window_y2[bx]
  ja edit_main_lbutton_notwin3

  sub cx, word ptr _window_x1[bx]
  sub dx, word ptr _window_y1[bx]
  mov bx, word ptr _window_proc[bx]
  cmp word ptr cs: [bx], 9090h
  jne edit_main_lbutton_error
  call bx
  jmp edit_main_lbutton_end

edit_main_lbutton_notwin3:

    ;  The background has been clicked on.

  call mouse_undo
  call mouse_get
  call mouse_draw
  call update

edit_main_lbutton_error:
edit_main_lbutton_end:
  pop bx
  pop dx
  pop cx
  pop ax

  call mouse_draw
  call update

  jmp edit_main_loop



  ;  Right mouse button event.

edit_main_rbutton:

  jmp edit_main_loop



;---- Edit_Redraw.

  ;  Draws the whole screen (except for mouse pointer).

edit_redraw:
  push ax
  push bx

    ;  Draw background.

  call edit_back

    ;  Draw windows in right order.

  mov bx, _worder[4]
  mov bx, word ptr _window_proc[bx]
  cmp word ptr cs: [bx], 9090h
  jne edit_redraw_error
  xor ax, ax
  call bx

  mov bx, _worder[2]
  mov bx, word ptr _window_proc[bx]
  cmp word ptr cs: [bx], 9090h
  jne edit_redraw_error
  xor ax, ax
  call bx

  mov bx, _worder[0]
  mov bx, word ptr _window_proc[bx]
  cmp word ptr cs: [bx], 9090h
  jne edit_redraw_error
  xor ax, ax
  call bx

edit_redraw_error:
  pop bx
  pop ax
  ret



;---- CharWin. ----------------------------------------------------------------;

charwin_proc:
  nop
  nop

  cmp ax, 00h		;  Redraw?
  je charwin_draw
  cmp ax, 10h		;  LButton pressed?
  je charwin_ldown
;  cmp ax, 11h		;  LButton released?
;  je charwin_lup
;  cmp ax, 20h		;  RButton pressed?
;  je charwin_rdown
;  cmp ax, 21h		;  RButton released?
;  je charwin_rup

  ret



;---- CharWin_LDown.

;  Left mouse button pressed.

charwin_ldown:
  push ax
  push cx
  push dx
  push bx
  push es

    ;  If within title bar then drag window.

  cmp cx, 11
  jb charwin_ldown_nodrag
  mov ax, _charwin_w
  sub ax, 12
  cmp cx, ax
  ja charwin_ldown_nodrag
  cmp dx, 1
  jb charwin_ldown_nodrag
  cmp dx, 9
  ja charwin_ldown_nodrag

    ;  Limit mouse.

  push dx
  mov ax, 0007h
  mov dx, cx
  add dx, 320
  add cx, cx
  sub dx, _charwin_w
  add dx, dx
  int 33h
  mov ax, 0008h
  pop dx
  mov cx, dx
  add dx, dx
  add cx, 200
  sub cx, _charwin_h
  add cx, cx
  int 33h

    ;  Drag window.

  mov es, _scr_seg

charwin_ldown_dragloop:

  call mouse_get

  mov cx, _mouse_x
  mov dx, _mouse_y
  sub cx, _mouse_xold
  sub dx, _mouse_yold

  add _charwin_x1, cx
  add _charwin_y1, dx
  add _charwin_x2, cx
  add _charwin_y2, dx

  mov ax, 320
  mul _charwin_y1
  add ax, _charwin_x1
  mov _charwin_off1, ax
  mov ax, 320
  mul _charwin_y2
  add ax, _charwin_x2
  mov _charwin_off2, ax

  call edit_redraw
  call mouse_draw
  call update

  test _mouse_b, 1
  jnz charwin_ldown_dragloop

  call mouse_limitscreen

  jmp charwin_ldown_end

charwin_ldown_nodrag:

    ;  Move to front.

  cmp _worder[4], 0
  jne charwin_ldown_nosort1
  mov ax, _worder[2]
  mov _worder[4], ax
  mov _worder[2], 0
charwin_ldown_nosort1:
  cmp _worder[2], 0
  jne charwin_ldown_nosort2
  mov ax, _worder[0]
  mov _worder[2], ax
  mov _worder, 0
charwin_ldown_nosort2:




charwin_ldown_end:

  pop es
  pop bx
  pop dx
  pop cx
  pop ax
  ret



;---- CharWin_Draw.

charwin_draw:

    ;  Title bar.

  mov bx, 0
  call edit_title

    ;  Horizontal scroll.

  mov di, _charwin_off2
  sub di, _charwin_w
  sub di, 320*10-1
  call edit_button
  add di, 320+11
  mov cx, _charwin_w
  sub cx, 33
  mov dx, 9
  mov al, 7
  call edit_rect
  mov di, _charwin_off2
  sub di, 10*320+20
  call edit_button
  add di, 10
  call edit_button

    ;  Draw characters.

  mov di, _charwin_off1
  add di, 10*320
  mov cx, _charwin_w
  sub cx, 10
  mov dx, _charwin_h
  sub dx, 20
  mov al, 0
  call edit_frame

  mov di, _charwin_off1
  add di, 1+11*320
  xor si, si
  mov ds, _sprite_seg

  mov dl, 16
edit_charwin_xloop:
  push si
  push di

  mov ax, _charwin_h
  sub ax, 22
  mov dh, al
edit_charwin_yloop:
  mov eax, [si]
  mov ebx, [si+4]
  mov es: [di], eax
  mov es: [di+4], ebx
  mov eax, [si+8]
  mov ebx, [si+12]
  mov es: [di+8], eax
  mov es: [di+12], ebx

  add di, 320
  add si, 16
  dec dh
  jnz edit_charwin_yloop

  pop di
  pop si
  add di, 16
  add si, 16*16*8
  dec dl
  jnz edit_charwin_xloop

  ret



;---- MapWin. -----------------------------------------------------------------;


_mapwin_chars	db 00h, 00h, 00h, 00h	;  Space.
		db 00h, 00h, 00h, 00h
		db 00h, 00h, 00h, 00h
		db 00h, 00h, 00h, 00h

		db 29h, 29h, 27h, 28h	;  Earth.
		db 2Ah, 29h, 28h, 29h
		db 29h, 28h, 28h, 27h
		db 26h, 27h, 28h, 28h

		db 00h, 00h, 4Dh, 00h	;  Diamond.
		db 00h, 4Dh, 46h, 4Dh
		db 4Dh, 46h, 46h, 46h
		db 00h, 4Dh, 46h, 4Dh

		db 00h, 00h, 16h, 00h	;  NewDia.
		db 00h, 16h, 10h, 16h
		db 16h, 10h, 10h, 10h
		db 00h, 16h, 10h, 16h

		db 4Dh, 00h, 4Dh, 00h	;  Bat.
		db 4Dh, 46h, 4Dh, 46h
		db 4Dh, 46h, 46h, 46h
		db 00h, 46h, 00h, 46h

		db 0AAh,0AAh,0AAh, 00h	;  Spirit.
		db 0AAh, 93h, 93h, 93h
		db 0AAh, 93h, 94h, 93h
		db 0AAh, 93h, 93h, 93h

		db 00h, 1Ch, 1Bh, 1Ch	;  Rock.
		db 1Ch, 1Ah, 18h, 1Ah
		db 1Bh, 18h, 17h, 18h
		db 1Ch, 1Ah, 18h, 1Ah

		db 12h, 15h, 12h, 15h	;  Wall.
		db 15h, 12h, 10h, 12h
		db 12h, 15h, 12h, 15h
		db 10h, 12h, 15h, 12h

		db 15h, 15h, 15h, 15h	;  Magic.
		db 13h, 10h, 10h, 13h
		db 10h, 13h, 13h, 10h
		db 15h, 15h, 15h, 15h

		db 00h, 00h, 00h, 00h	;  Bang.
		db 00h, 23h, 23h, 00h
		db 00h, 23h, 23h, 00h
		db 00h, 00h, 00h, 00h

		db 6Bh, 68h, 68h, 6Bh	;  Mould.
		db 68h, 6Bh, 6Bh, 68h
		db 68h, 6Bh, 6Bh, 68h
		db 6Bh, 68h, 68h, 6Bh

		db 6Ah, 6Ch, 6Ah, 6Ch	;  Solid.
		db 6Ch, 6Eh, 6Ch, 6Eh
		db 6Ah, 6Ch, 6Ah, 6Ch
		db 6Ch, 6Eh, 6Ch, 6Eh

		db 6Ch, 6Ch, 6Ch, 6Ch	;  Door.
		db 6Ch, 00h, 00h, 6Ch
		db 6Ch, 00h, 00h, 6Ch
		db 6Ch, 6Ch, 6Ch, 6Ch

		db 6Ah, 6Bh, 6Dh, 6Eh	;  RSolid.
		db 6Eh, 6Dh, 6Bh, 6Ah
		db 6Ah, 6Bh, 6Dh, 6Eh
		db 6Eh, 6Dh, 6Bh, 6Ah

		db 6Ah, 6Ah, 6Ah, 00h	;  Start.
		db 6Ah, 6Ah, 00h, 6Ah
		db 6Ah, 00h, 6Ah, 6Ah
		db 00h, 6Ah, 6Ah, 6Ah

		db 00h, 26h, 26h, 00h	;  Man.
		db 26h, 6Ch, 6Ch, 26h
		db 00h, 6Ch, 6Ch, 00h
		db 26h, 00h, 00h, 26h


;---- MapWin_Proc.

mapwin_proc:
  nop
  nop

  cmp ax, 00h		;  Redraw?
  je mapwin_draw
  cmp ax, 10h		;  LButton pressed?
  je mapwin_ldown
;  cmp ax, 11h		;  LButton released?
;  je mapwin_lup
;  cmp ax, 20h		;  RButton pressed?
;  je mapwin_rdown
;  cmp ax, 21h		;  RButton released?
;  je mapwin_rup

  ret



;---- MapWin_LDown.

;  Left mouse button pressed.

mapwin_ldown:
  push ax
  push cx
  push dx
  push bx
  push es

    ;  If within title bar then drag window.

  cmp cx, 11
  jb mapwin_ldown_nodrag
  mov ax, _mapwin_w
  sub ax, 12
  cmp cx, ax
  ja mapwin_ldown_nodrag
  cmp dx, 1
  jb mapwin_ldown_nodrag
  cmp dx, 9
  ja mapwin_ldown_nodrag

    ;  Limit mouse.

  push dx
  mov ax, 0007h
  mov dx, cx
  add dx, 320
  add cx, cx
  sub dx, _mapwin_w
  add dx, dx
  int 33h
  mov ax, 0008h
  pop dx
  mov cx, dx
  add dx, dx
  add cx, 200
  sub cx, _mapwin_h
  add cx, cx
  int 33h

    ;  Drag window.

  mov es, _scr_seg

mapwin_ldown_dragloop:

  call mouse_get

  mov cx, _mouse_x
  mov dx, _mouse_y
  sub cx, _mouse_xold
  sub dx, _mouse_yold

  add _mapwin_x1, cx
  add _mapwin_y1, dx
  add _mapwin_x2, cx
  add _mapwin_y2, dx

  mov ax, 320
  mul _mapwin_y1
  add ax, _mapwin_x1
  mov _mapwin_off1, ax
  mov ax, 320
  mul _mapwin_y2
  add ax, _mapwin_x2
  mov _mapwin_off2, ax

  call edit_redraw
  call mouse_draw
  call update

  test _mouse_b, 1
  jnz mapwin_ldown_dragloop

  call mouse_limitscreen

  jmp mapwin_ldown_end

mapwin_ldown_nodrag:

    ;  Move to front.

  cmp _worder[4], 32
  jne mapwin_ldown_nosort1
  mov ax, _worder[2]
  mov _worder[4], ax
  mov _worder[2], 32
mapwin_ldown_nosort1:
  cmp _worder[2], 32
  jne mapwin_ldown_nosort2
  mov ax, _worder[0]
  mov _worder[2], ax
  mov _worder, 32
mapwin_ldown_nosort2:




mapwin_ldown_end:

  pop es
  pop bx
  pop dx
  pop cx
  pop ax
  ret



;---- MapWin_Draw.

mapwin_draw:
  push eax
  push cx
  push dx
  push di

  mov bx, 32
  call edit_title

    ;  Info bar.

  mov di, _mapwin_off1
  add di, 10*320
  mov cx, 53
  mov dx, 11
  call edit_box

  add di, 52
  mov ax, 2
  call edit_button

  add di, 10
  mov ax, 3
  call edit_button

    ;  Map.

  mov cx, _mapwin_w
  mov dx, _mapwin_h
  mov di, _mapwin_off1
  sub cx, 10
  sub dx, 20
  add di, 20*320
  mov al, 0
  call edit_frame

  shr cx, 2
  shr dx, 2

  xor si, si
  mov di, _mapwin_off1
  add di, 320*21+1
mapwin_draw_yloop:

  push di
  push cx

mapwin_draw_xloop:

  mov bl, cs: _level[si]
  xor bh, bh
  and bl, 0F0h
  mov eax, dword ptr _mapwin_chars[bx]
  mov es: [di], eax
  mov eax, dword ptr _mapwin_chars[bx+4]
  mov es: [di+320], eax
  mov eax, dword ptr _mapwin_chars[bx+8]
  mov es: [di+320*2], eax
  mov eax, dword ptr _mapwin_chars[bx+12]
  mov es: [di+320*3], eax

  inc si
  add di, 4
  loop mapwin_draw_xloop

  pop cx
  pop di
  add di, 320*4
  dec dx
  jnz mapwin_draw_yloop


  call game_move


  pop di
  pop dx
  pop cx
  pop eax
  ret



;---- EditWin. ----------------------------------------------------------------;


;---- EditWin_Proc.

editwin_proc:
  nop
  nop

  cmp ax, 00h		;  Redraw?
  je editwin_draw
  cmp ax, 10h		;  LButton pressed?
  je editwin_ldown
;  cmp ax, 11h		;  LButton released?
;  je editwin_lup
;  cmp ax, 20h		;  RButton pressed?
;  je editwin_rdown
;  cmp ax, 21h		;  RButton released?
;  je editwin_rup

  ret



;---- EditWin_LDown.

;  Left mouse button pressed.

editwin_ldown:
  push ax
  push cx
  push dx
  push bx
  push es

    ;  If within title bar then drag window.

  cmp cx, 11
  jb editwin_ldown_nodrag
  mov ax, _editwin_w
  sub ax, 12
  cmp cx, ax
  ja editwin_ldown_nodrag
  cmp dx, 1
  jb editwin_ldown_nodrag
  cmp dx, 9
  ja editwin_ldown_nodrag

    ;  Limit mouse.

  push dx
  mov ax, 0007h
  mov dx, cx
  add dx, 320
  add cx, cx
  sub dx, _editwin_w
  add dx, dx
  int 33h
  mov ax, 0008h
  pop dx
  mov cx, dx
  add dx, dx
  add cx, 200
  sub cx, _editwin_h
  add cx, cx
  int 33h

    ;  Drag window.

  mov es, _scr_seg

editwin_ldown_dragloop:

  call mouse_get

  mov cx, _mouse_x
  mov dx, _mouse_y
  sub cx, _mouse_xold
  sub dx, _mouse_yold

  add _editwin_x1, cx
  add _editwin_y1, dx
  add _editwin_x2, cx
  add _editwin_y2, dx

  mov ax, 320
  mul _editwin_y1
  add ax, _editwin_x1
  mov _editwin_off1, ax
  mov ax, 320
  mul _editwin_y2
  add ax, _editwin_x2
  mov _editwin_off2, ax

  call edit_redraw
  call mouse_draw
  call update

  test _mouse_b, 1
  jnz editwin_ldown_dragloop

  call mouse_limitscreen

  jmp editwin_ldown_end

editwin_ldown_nodrag:

    ;  Move to front.

  cmp _worder[4], 64
  jne editwin_ldown_nosort1
  mov ax, _worder[2]
  mov _worder[4], ax
  mov _worder[2], 64
editwin_ldown_nosort1:
  cmp _worder[2], 64
  jne editwin_ldown_nosort2
  mov ax, _worder[0]
  mov _worder[2], ax
  mov _worder, 64
editwin_ldown_nosort2:




editwin_ldown_end:

  pop es
  pop bx
  pop dx
  pop cx
  pop ax
  ret



;---- EditWin_Draw.

editwin_draw:
  push ax
  push cx
  push dx
  push di

  mov bx, 64
  call edit_title

  mov cx, _editwin_w
  mov dx, _editwin_h
  mov di, _editwin_off1
  sub dx, 10
  add di, 10*320
  call edit_box

  pop di
  pop dx
  pop cx
  pop ax
  ret



;---- Mouse routines. ---------------------------------------------------------;


_mouse_offs	dw 0000h

_mouse_and	db  0,  0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
		db  0,  0,  0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
		db  0,  0,  0,  0, -1, -1, -1, -1, -1, -1, -1, -1, -1
		db  0,  0,  0,  0,  0, -1, -1, -1, -1, -1, -1, -1, -1
		db  0,  0,  0,  0,  0,  0, -1, -1, -1, -1, -1, -1, -1
		db  0,  0,  0,  0,  0,  0,  0, -1, -1, -1, -1, -1, -1
		db  0,  0,  0,  0,  0,  0,  0,  0, -1, -1, -1, -1, -1
		db  0,  0,  0,  0,  0,  0,  0,  0,  0, -1, -1, -1, -1
		db  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, -1, -1, -1
		db  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, -1, -1
		db  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, -1
		db  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0
		db  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, -1
		db  0,  0,  0,  0,  0,  0,  0,  0,  0, -1, -1, -1, -1
		db  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, -1, -1, -1
		db  0,  0,  0, -1,  0,  0,  0,  0,  0,  0, -1, -1, -1
		db -1,  0, -1, -1, -1,  0,  0,  0,  0,  0,  0, -1, -1
		db -1, -1, -1, -1, -1,  0,  0,  0,  0,  0,  0, -1, -1
		db -1, -1, -1, -1, -1, -1,  0,  0,  0,  0, -1, -1, -1
		db -1, -1, -1, -1, -1, -1, -1,  0,  0, -1, -1, -1, -1
_mouse_xor	db  0h, 0h, 0h, 0h, 0h, 0h, 0h, 0h, 0h, 0h, 0h, 0h, 0
		db  0h,0Fh, 0h, 0h, 0h, 0h, 0h, 0h, 0h, 0h, 0h, 0h, 0
		db  0h,0Fh,0Fh, 0h, 0h, 0h, 0h, 0h, 0h, 0h, 0h, 0h, 0
		db  0h,0Fh,28h,0Fh, 0h, 0h, 0h, 0h, 0h, 0h, 0h, 0h, 0
		db  0h,0Fh,28h,28h,0Fh, 0h, 0h, 0h, 0h, 0h, 0h, 0h, 0
		db  0h,0Fh,29h,2Bh,28h,0Fh, 0h, 0h, 0h, 0h, 0h, 0h, 0
		db  0h,0Fh,2Ah,2Bh,2Ch,28h,0Fh, 0h, 0h, 0h, 0h, 0h, 0
		db  0h,0Fh,29h,2Ah,2Bh,2Dh,29h,0Fh, 0h, 0h, 0h, 0h, 0
		db  0h,0Fh,28h,29h,2Ah,2Bh,2Ch,2Ah,0Fh, 0h, 0h, 0h, 0
		db  0h,0Fh,28h,28h,29h,2Ah,2Ch,2Dh,2Ah,0Fh, 0h, 0h, 0
		db  0h,0Fh,27h,22h,27h,29h,2Ah,2Bh,2Ah,2Ah,0Fh, 0h, 0
		db  0h,0Fh,27h,27h,28h,28h,29h,2Ah,0Fh,0Fh,0Fh,0Fh, 0
		db  0h,0Fh,27h,28h,28h,29h,29h,0Fh, 0h, 0h, 0h, 0h, 0
		db  0h,0Fh,27h,0Fh,0Fh,29h,2Ah,0Fh, 0h, 0h, 0h, 0h, 0
		db  0h,0Fh,0Fh, 0h, 0h,0Fh,2Ah,29h,0Fh, 0h, 0h, 0h, 0
		db  0h,0Fh, 0h, 0h, 0h,0Fh,28h,2Ah,0Fh, 0h, 0h, 0h, 0
		db  0h, 0h, 0h, 0h, 0h, 0h,0Fh,29h,2Ah,0Fh, 0h, 0h, 0
		db  0h, 0h, 0h, 0h, 0h, 0h,0Fh,29h,28h,0Fh, 0h, 0h, 0
		db  0h, 0h, 0h, 0h, 0h, 0h, 0h,0Fh,0Fh, 0h, 0h, 0h, 0
		db  0h, 0h, 0h, 0h, 0h, 0h, 0h, 0h, 0h, 0h, 0h, 0h, 0
_mouse_add	db  0h, 0h, 0h, 0h, 0h, 0h, 0h, 0h, 0h, 0h, 0h, 0h, 0
		db  0h,01h, 0h, 0h, 0h, 0h, 0h, 0h, 0h, 0h, 0h, 0h, 0
		db  0h,01h,01h, 0h, 0h, 0h, 0h, 0h, 0h, 0h, 0h, 0h, 0
		db  0h,01h,01h,01h, 0h, 0h, 0h, 0h, 0h, 0h, 0h, 0h, 0
		db  0h,01h,01h,01h,01h, 0h, 0h, 0h, 0h, 0h, 0h, 0h, 0
		db  0h,01h,01h,01h,01h,01h, 0h, 0h, 0h, 0h, 0h, 0h, 0
		db  0h,01h,01h,01h,01h,01h,01h, 0h, 0h, 0h, 0h, 0h, 0
		db  0h,01h,01h,01h,01h,01h,01h,01h, 0h, 0h, 0h, 0h, 0
		db  0h,01h,01h,01h,01h,01h,01h,01h,01h, 0h, 0h, 0h, 0
		db  0h,01h,01h,01h,01h,01h,01h,01h,01h,01h, 0h, 0h, 0
		db  0h,01h,01h,01h,01h,01h,01h,01h,01h,01h,01h, 0h, 0
		db  0h,01h,01h,01h,01h,01h,01h,01h,01h,01h,01h,01h, 0
		db  0h,01h,01h,01h,01h,01h,01h,01h, 0h, 0h, 0h, 0h, 0
		db  0h,01h,01h,01h,01h,01h,01h,01h, 0h, 0h, 0h, 0h, 0
		db  0h,01h,01h, 0h, 0h,01h,01h,01h,01h, 0h, 0h, 0h, 0
		db  0h,01h, 0h, 0h, 0h,01h,01h,01h,01h, 0h, 0h, 0h, 0
		db  0h, 0h, 0h, 0h, 0h, 0h,01h,01h,01h,01h, 0h, 0h, 0
		db  0h, 0h, 0h, 0h, 0h, 0h,01h,01h,01h,01h, 0h, 0h, 0
		db  0h, 0h, 0h, 0h, 0h, 0h, 0h,01h,01h, 0h, 0h, 0h, 0
		db  0h, 0h, 0h, 0h, 0h, 0h, 0h, 0h, 0h, 0h, 0h, 0h, 0
_mouse_under	db  0h, 0h, 0h, 0h, 0h, 0h, 0h, 0h, 0h, 0h, 0h, 0h, 0
		db  0h,01h, 0h, 0h, 0h, 0h, 0h, 0h, 0h, 0h, 0h, 0h, 0
		db  0h,01h,01h, 0h, 0h, 0h, 0h, 0h, 0h, 0h, 0h, 0h, 0
		db  0h,01h,01h,01h, 0h, 0h, 0h, 0h, 0h, 0h, 0h, 0h, 0
		db  0h,01h,01h,01h,01h, 0h, 0h, 0h, 0h, 0h, 0h, 0h, 0
		db  0h,01h,01h,01h,01h,01h, 0h, 0h, 0h, 0h, 0h, 0h, 0
		db  0h,01h,01h,01h,01h,01h,01h, 0h, 0h, 0h, 0h, 0h, 0
		db  0h,01h,01h,01h,01h,01h,01h,01h, 0h, 0h, 0h, 0h, 0
		db  0h,01h,01h,01h,01h,01h,01h,01h,01h, 0h, 0h, 0h, 0
		db  0h,01h,01h,01h,01h,01h,01h,01h,01h,01h, 0h, 0h, 0
		db  0h,01h,01h,01h,01h,01h,01h,01h,01h,01h,01h, 0h, 0
		db  0h,01h,01h,01h,01h,01h,01h,01h,01h,01h,01h,01h, 0
		db  0h,01h,01h,01h,01h,01h,01h,01h, 0h, 0h, 0h, 0h, 0
		db  0h,01h,01h,01h,01h,01h,01h,01h, 0h, 0h, 0h, 0h, 0
		db  0h,01h,01h, 0h, 0h,01h,01h,01h,01h, 0h, 0h, 0h, 0
		db  0h,01h, 0h, 0h, 0h,01h,01h,01h,01h, 0h, 0h, 0h, 0
		db  0h, 0h, 0h, 0h, 0h, 0h,01h,01h,01h,01h, 0h, 0h, 0
		db  0h, 0h, 0h, 0h, 0h, 0h,01h,01h,01h,01h, 0h, 0h, 0
		db  0h, 0h, 0h, 0h, 0h, 0h, 0h,01h,01h, 0h, 0h, 0h, 0
		db  0h, 0h, 0h, 0h, 0h, 0h, 0h, 0h, 0h, 0h, 0h, 0h, 0



;---- Mouse_Get.

;  Gets mouse co-ordinates and button status.

mouse_get:
  push ax
  push cx
  push dx
  push bx

  mov cx, _mouse_x
  mov dx, _mouse_y
  mov _mouse_xold, cx
  mov _mouse_yold, dx

  mov ax, 0003h
  int 33h
  shr cx, 1
  shr dx, 1
  mov _mouse_b, bx
  mov _mouse_x, cx
  mov _mouse_y, dx

  pop bx
  pop dx
  pop cx
  pop ax
  ret



;---- Mouse_Undo.

;  Removes pointer and replaces whatever was covered by it.  Uses _mouse_offs,
; which is set by the drawing routine, so if _mouse_x etc. have been changed
; the pointer will still be removed in the right place.

mouse_undo:
  push eax
  push ebx
  push cx
  push si
  push di

  xor si, si
  mov di, _mouse_offs
  mov cx, 20
mouse_undo_loop:

  mov eax, dword ptr _mouse_under[si]
  mov ebx, dword ptr _mouse_under[si+4]
  mov es: [di], eax
  mov es: [di+4], ebx
  mov eax, dword ptr _mouse_under[si+8]
  mov bl,  byte  ptr _mouse_under[si+12]
  mov es: [di+8], eax
  mov es: [di+12], bl

  add si, 13
  add di, 320

    ;  Clip to bottom of screen.
  cmp di, 64000
  jae mouse_undo_end

  loop mouse_undo_loop

mouse_undo_end:
  pop di
  pop si
  pop cx
  pop ebx
  pop eax
  ret



;---- Mouse_Draw.

;  Displays mouse pointer according to _mouse_x etc. and stores the rectangle
; of pixels under it.

mouse_draw:
  push eax
  push ebx
  push cx
  push dx
  push si
  push di

  mov dx, _mouse_y
  mov ax, 320
  mul dx
  add ax, _mouse_x
  mov di, ax
  mov _mouse_offs, di

  xor si, si
  mov cx, 20
mouse_draw_loop:

    ;  Get pixels underneath.
  mov eax, es: [di]
  mov ebx, es: [di+4]
  mov dword ptr _mouse_under[si], eax
  mov dword ptr _mouse_under[si+4], ebx
  mov eax, es: [di+8]
  mov bl, es: [di+12]
  mov dword ptr _mouse_under[si+8], eax
  mov byte  ptr _mouse_under[si+12], bl

    ;  And mask.
  mov eax, dword ptr _mouse_and[si]
  mov ebx, dword ptr _mouse_and[si+4]
  and es: [di], eax
  and es: [di+4], ebx
  mov eax, dword ptr _mouse_and[si+8]
  mov bl,  byte  ptr _mouse_and[si+12]
  and es: [di+8], eax
  and es: [di+12], bl

    ;  Xor mask.
  mov eax, dword ptr _mouse_xor[si]
  mov ebx, dword ptr _mouse_xor[si+4]
  xor es: [di], eax
  xor es: [di+4], ebx
  mov eax, dword ptr _mouse_xor[si+8]
  mov bl,  byte  ptr _mouse_xor[si+12]
  xor es: [di+8], eax
  xor es: [di+12], bl

    ;  Shadow.
;  mov eax, dword ptr _mouse_add[si]
;  mov ebx, dword ptr _mouse_add[si+4]
;  add es: [di+320*8+8], eax
;  add es: [di+320*8+8+4], ebx
;  mov eax, dword ptr _mouse_add[si+8]
;  mov bl,  byte  ptr _mouse_add[si+12]
;  add es: [di++320*8+8+8], eax
;  add es: [di++320*8+8+12], bl

  add si, 13
  add di, 320

  cmp di, 64000
  jae mouse_draw_end

  loop mouse_draw_loop

mouse_draw_end:
  pop di
  pop si
  pop dx
  pop cx
  pop ebx
  pop eax
  ret



;---- Mouse_LimitScreen.

;  Sets the mouse limits to the whole screen.

mouse_limitscreen:
  push ax
  push cx
  push dx

  mov ax, 0007h
  mov cx, 2
  mov dx, 318*2
  int 33h
  mov ax, 0008h
  mov cx, 2
  mov dx, 198*2
  int 33h

  pop dx
  pop cx
  pop ax
  ret



;---- Editor graphics. --------------------------------------------------------;


;---- Edit_Title.

;  Draws a title bar with Close and Under buttons.

;  Inputs:
;    BX - Window structure (0, 32 or 64).
;    ES - Output buffer.

edit_title:
  push ax
  push cx
  push dx

  mov di, word ptr _window_off1[bx]
  mov ax, 0
  call edit_button

  add di, 10
  mov cx, word ptr _window_w[bx]
  mov dx, 11
  sub cx, 20
  call edit_box

  add di, word ptr _window_w[bx]
  sub di, 21
  mov ax, 1
  call edit_button

  pop dx
  pop cx
  pop ax
  ret



;---- Edit_Button.

  ;  Button bitmaps.

_edit_buttons	db 48h, 48h, 48h, 48h, 48h, 48h, 48h, 48h, 4Bh	;  Close.
		db 48h, 4Bh, 4Bh, 4Bh, 4Bh, 4Bh, 4Bh, 4Bh, 4Eh
		db 48h, 4Bh,  0h,  0h, 4Bh,  0h,  0h, 4Bh, 4Eh
		db 48h, 4Bh,  0h,  0h,  0h,  0h,  0h, 4Bh, 4Eh
		db 48h, 4Bh, 4Bh,  0h, 4Bh,  0h, 4Bh, 4Bh, 4Eh
		db 48h, 4Bh,  0h,  0h,  0h,  0h,  0h, 4Bh, 4Eh
		db 48h, 4Bh,  0h,  0h, 4Bh,  0h,  0h, 4Bh, 4Eh
		db 48h, 4Bh, 4Bh, 4Bh, 4Bh, 4Bh, 4Bh, 4Bh, 4Eh
		db 4Bh, 4Eh, 4Eh, 4Eh, 4Eh, 4Eh, 4Eh, 4Eh, 4Eh

		db 48h, 48h, 48h, 48h, 48h, 48h, 48h, 48h, 4Bh	;  Under.
		db 48h, 4Bh, 4Bh, 4Bh, 4Bh, 4Bh, 4Bh, 4Bh, 4Eh
		db 48h, 4Bh,  0h,  0h,  0h, 4Bh, 4Bh, 4Bh, 4Eh
		db 48h, 4Bh,  0h,  0h,  0h,  0h,  0h, 4Bh, 4Eh
		db 48h, 4Bh,  0h,  0h, 4Bh, 4Bh,  0h, 4Bh, 4Eh
		db 48h, 4Bh, 4Bh,  0h, 4Bh, 4Bh,  0h, 4Bh, 4Eh
		db 48h, 4Bh, 4Bh,  0h,  0h,  0h,  0h, 4Bh, 4Eh
		db 48h, 4Bh, 4Bh, 4Bh, 4Bh, 4Bh, 4Bh, 4Bh, 4Eh
		db 4Bh, 4Eh, 4Eh, 4Eh, 4Eh, 4Eh, 4Eh, 4Eh, 4Eh

		db 48h, 48h, 48h, 48h, 48h, 48h, 48h, 48h, 4Bh	;  Left.
		db 48h, 4Bh, 4Bh, 4Bh, 4Bh, 4Bh, 4Bh, 4Bh, 4Eh
		db 48h, 4Bh, 4Bh, 4Bh,  0h, 4Bh, 4Bh, 4Bh, 4Eh
		db 48h, 4Bh, 4Bh,  0h,  0h,  0h,  0h, 4Bh, 4Eh
		db 48h, 4Bh,  0h,  0h,  0h,  0h,  0h, 4Bh, 4Eh
		db 48h, 4Bh, 4Bh,  0h,  0h,  0h,  0h, 4Bh, 4Eh
		db 48h, 4Bh, 4Bh, 4Bh,  0h, 4Bh, 4Bh, 4Bh, 4Eh
		db 48h, 4Bh, 4Bh, 4Bh, 4Bh, 4Bh, 4Bh, 4Bh, 4Eh
		db 4Bh, 4Eh, 4Eh, 4Eh, 4Eh, 4Eh, 4Eh, 4Eh, 4Eh

		db 48h, 48h, 48h, 48h, 48h, 48h, 48h, 48h, 4Bh	;  Right.
		db 48h, 4Bh, 4Bh, 4Bh, 4Bh, 4Bh, 4Bh, 4Bh, 4Eh
		db 48h, 4Bh, 4Bh, 4Bh,  0h, 4Bh, 4Bh, 4Bh, 4Eh
		db 48h, 4Bh,  0h,  0h,  0h,  0h, 4Bh, 4Bh, 4Eh
		db 48h, 4Bh,  0h,  0h,  0h,  0h,  0h, 4Bh, 4Eh
		db 48h, 4Bh,  0h,  0h,  0h,  0h, 4Bh, 4Bh, 4Eh
		db 48h, 4Bh, 4Bh, 4Bh,  0h, 4Bh, 4Bh, 4Bh, 4Eh
		db 48h, 4Bh, 4Bh, 4Bh, 4Bh, 4Bh, 4Bh, 4Bh, 4Eh
		db 4Bh, 4Eh, 4Eh, 4Eh, 4Eh, 4Eh, 4Eh, 4Eh, 4Eh

		db 48h, 48h, 48h, 48h, 48h, 48h, 48h, 48h, 4Bh	;  Up.
		db 48h, 4Bh, 4Bh, 4Bh, 4Bh, 4Bh, 4Bh, 4Bh, 4Eh
		db 48h, 4Bh, 4Bh, 4Bh,  0h, 4Bh, 4Bh, 4Bh, 4Eh
		db 48h, 4Bh, 4Bh,  0h,  0h,  0h, 4Bh, 4Bh, 4Eh
		db 48h, 4Bh,  0h,  0h,  0h,  0h,  0h, 4Bh, 4Eh
		db 48h, 4Bh, 4Bh,  0h,  0h,  0h, 4Bh, 4Bh, 4Eh
		db 48h, 4Bh, 4Bh,  0h,  0h,  0h, 4Bh, 4Bh, 4Eh
		db 48h, 4Bh, 4Bh, 4Bh, 4Bh, 4Bh, 4Bh, 4Bh, 4Eh
		db 4Bh, 4Eh, 4Eh, 4Eh, 4Eh, 4Eh, 4Eh, 4Eh, 4Eh

		db 48h, 48h, 48h, 48h, 48h, 48h, 48h, 48h, 4Bh	;  Down.
		db 48h, 4Bh, 4Bh, 4Bh, 4Bh, 4Bh, 4Bh, 4Bh, 4Eh
		db 48h, 4Bh, 4Bh,  0h,  0h,  0h, 4Bh, 4Bh, 4Eh
		db 48h, 4Bh, 4Bh,  0h,  0h,  0h, 4Bh, 4Bh, 4Eh
		db 48h, 4Bh,  0h,  0h,  0h,  0h,  0h, 4Bh, 4Eh
		db 48h, 4Bh, 4Bh,  0h,  0h,  0h, 4Bh, 4Bh, 4Eh
		db 48h, 4Bh, 4Bh, 4Bh,  0h, 4Bh, 4Bh, 4Bh, 4Eh
		db 48h, 4Bh, 4Bh, 4Bh, 4Bh, 4Bh, 4Bh, 4Bh, 4Eh
		db 4Bh, 4Eh, 4Eh, 4Eh, 4Eh, 4Eh, 4Eh, 4Eh, 4Eh

		db 48h, 48h, 48h, 48h, 48h, 48h, 48h, 48h, 4Bh	;  Resize.
		db 48h, 4Bh, 4Bh, 4Bh, 4Bh, 4Bh, 4Bh, 4Bh, 4Eh
		db 48h, 4Bh,  0h,  0h,  0h, 4Bh,  0h, 4Bh, 4Eh
		db 48h, 4Bh,  0h, 4Bh,  0h, 4Bh, 4Bh, 4Bh, 4Eh
		db 48h, 4Bh,  0h,  0h,  0h, 4Bh,  0h, 4Bh, 4Eh
		db 48h, 4Bh, 4Bh, 4Bh, 4Bh, 4Bh, 4Bh, 4Bh, 4Eh
		db 48h, 4Bh,  0h, 4Bh,  0h, 4Bh,  0h, 4Bh, 4Eh
		db 48h, 4Bh, 4Bh, 4Bh, 4Bh, 4Bh, 4Bh, 4Bh, 4Eh
		db 4Bh, 4Eh, 4Eh, 4Eh, 4Eh, 4Eh, 4Eh, 4Eh, 4Eh

		db 48h, 48h, 48h, 48h, 48h, 48h, 48h, 48h, 4Bh	;  Blank.
		db 48h, 4Bh, 4Bh, 4Bh, 4Bh, 4Bh, 4Bh, 4Bh, 4Eh
		db 48h, 4Bh, 4Bh, 4Bh, 4Bh, 4Bh, 4Bh, 4Bh, 4Eh
		db 48h, 4Bh, 4Bh, 4Bh, 4Bh, 4Bh, 4Bh, 4Bh, 4Eh
		db 48h, 4Bh, 4Bh, 4Bh, 4Bh, 4Bh, 4Bh, 4Bh, 4Eh
		db 48h, 4Bh, 4Bh, 4Bh, 4Bh, 4Bh, 4Bh, 4Bh, 4Eh
		db 48h, 4Bh, 4Bh, 4Bh, 4Bh, 4Bh, 4Bh, 4Bh, 4Eh
		db 48h, 4Bh, 4Bh, 4Bh, 4Bh, 4Bh, 4Bh, 4Bh, 4Eh
		db 4Bh, 4Eh, 4Eh, 4Eh, 4Eh, 4Eh, 4Eh, 4Eh, 4Eh


;  ES:DI - offset, AX - button number.

edit_button:
  push eax
  push cx
  push bx
  push si
  push di

  add di, 321

  mov bx, 81
  mul bx
  mov si, ax

  mov cx, 9
edit_button_loop:
  mov eax, dword ptr _edit_buttons[si]
  mov es: [di], eax
  mov eax, dword ptr _edit_buttons[si+4]
  mov es: [di+4], eax
  mov al, byte ptr _edit_buttons[si+8]
  mov es: [di+8], al
  add si, 9
  add di, 320
  loop edit_button_loop

  pop di

  mov cx, 11
  mov dx, 11
  mov al, 0
  call edit_frame

  pop si
  pop bx
  pop cx
  pop eax
  ret



;---- Edit_HBar.

;  ES:DI - offset, CX - width.

_edit_hbar_width	dw 0000h

edit_hbar:
  push ax
  push bx
  push cx
  push dx
  push di

  mov _edit_hbar_width, cx

  mov dx, 11
  mov al, 0
  call edit_frame

  add di, 321
  sub cx, 2
  mov dl, 9
  mov al, 8
  call edit_rect
  mov dx, 1
  dec cx
  mov al, 15
  call edit_rect
  mov cx, 1
  mov dx, 8
  call edit_rect
  add di, _edit_hbar_width
  add di, 317
  mov al, 7
  call edit_rect
  mov cx, _edit_hbar_width
  sub cx, 3
  sub di, cx
  add di, 1+320*7
  mov dx, 1
  call edit_rect

  pop di
  pop dx
  pop cx
  pop bx
  pop ax

  ret



;---- Edit_VBar.

edit_vbar:

  ret



;---- Edit_Back.

;  Draw tiled background.

edit_back:

  mov ds, _intro_seg
  mov si, 2
  xor di, di

  mov dx, 100
edit_yback:
  push si
  push di

  mov eax, [si]
  mov es: [di+300], eax
  mov es: [di+32300], eax
  mov eax, [si+4]
  mov es: [di+304], eax
  mov es: [di+32304], eax
  mov eax, [si+8]
  mov es: [di+308], eax
  mov es: [di+32308], eax
  mov eax, [si+12]
  mov es: [di+312], eax
  mov es: [di+32312], eax
  mov eax, [si+16]
  mov es: [di+316], eax
  mov es: [di+32316], eax

  mov cx, 25
edit_xback:
  mov eax, [si]
  mov es: [di], eax
  mov es: [di+100], eax
  mov es: [di+200], eax
  mov es: [di+32000], eax
  mov es: [di+32100], eax
  mov es: [di+32200], eax
  mov [si-1], eax
  add si, 4
  add di, 4
  loop edit_xback

  pop di
  pop si

  mov al, [si-1]
  mov [si+99], al
  add di, 320
  add si, 102

  dec dx
  jnz edit_yback

  ret



;---- Edit_Box.

;  Draws a raised box.

;  CX - Width of box.
;  DX - Height of box.
;  ES:DI - Destination.

_edit_box_offs	dw 0000h
_edit_box_w	dw 0000h
_edit_box_h	dw 0000h

edit_box:
  push ax
  push cx
  push dx
  push di

  mov _edit_box_offs, di
  mov _edit_box_w, cx
  mov _edit_box_h, dx

  mov al, 0
  call edit_frame

  add di, 321
  sub cx, 2
  sub dx, 2
  mov al, 8
  call edit_rect

  dec cx
  mov dx, 1
  mov al, 15
  call edit_rect
  mov cx, 1
  mov dx, _edit_box_h
  sub dx, 3
  call edit_rect

  mov ax, 320
  mul _edit_box_h
  sub ax, 319
  mov di, _edit_box_offs
  add di, ax
  mov cx, _edit_box_w
  mov dx, 1
  sub di, 319
  sub cx, 3
  mov al, 7
  call edit_rect

  mov di, _edit_box_offs
  mov cx, 1
  add di, _edit_box_w
  mov dx, _edit_box_h
  add di, 638
  sub dx, 3
  call edit_rect

  pop di
  pop dx
  pop cx
  pop ax
  ret



;---- Edit_Frame.

;  ES:DI - Offset, CX*DX size, AL colour.

edit_frame:
  push ax
  push bx
  push cx
  push dx
  push di

  mov bx, cx
  dec bx
edit_frame_vertloop:
  mov es: [di], al
  mov es: [di+bx], al
  add di, 320
  dec dx
  jnz edit_frame_vertloop

  pop di
  pop dx
  push dx
  push di

  push ax
  mov bx, dx
  mov ax, 320
  dec bx
  mul bx
  mov bx, ax
  pop ax
edit_frame_horizloop:
  mov es: [di], al
  mov es: [di+bx], al
  inc di
  loop edit_frame_horizloop

  pop di
  pop dx
  pop cx
  pop bx
  pop ax
  ret



;---- Edit_Rect.

;  ES:DI - Offset, rectangle CX by DX pixels. AL - colour.

edit_rect:

  cmp dx, 0
  je edit_rect_end
  jcxz edit_rect_end

  push eax
  push cx
  push dx
  push di

  mov ah, al
  ror eax, 8
  mov ah, al
  ror eax, 8
  mov ah, al

edit_rect_loop:
  push cx
  push di

  shr cx, 1
  jnc edit_rect_nobyte
  stosb
  jcxz edit_rect_next
edit_rect_nobyte:
  shr cx, 1
  jnc edit_rect_noword
  stosw
  jcxz edit_rect_next
edit_rect_noword:
  rep stosd
edit_rect_next:

;  rep stosb

  pop di
  pop cx
  add di, 320
  dec dx
  jnz edit_rect_loop

  pop di
  pop dx
  pop cx
  pop eax
edit_rect_end:
  ret



;---- INTRO -------------------------------------------------------------------;


  ;  Background bitmap (4 colours).


_intro_back  db 230, 153, 123, 119, 190, 122, 106, 86, 150, 157, 167, 254, 107, 86, 191, 239, 103, 151, 153, 101, 166, 102, 87, 106, 90
  db 234, 254, 187, 119, 175, 122, 254, 251, 238, 158, 166, 90, 245, 187, 86, 150, 166, 247, 238, 106, 170, 122, 231, 170, 154
  db 170, 85, 85, 102, 102, 117, 94, 149, 217, 221, 238, 255, 107, 85, 187, 255, 183, 167, 153, 165, 255, 127, 167, 169, 174
  db 234, 170, 170, 251, 191, 127, 175, 234, 237, 157, 153, 85, 181, 187, 119, 103, 102, 231, 221, 169, 87, 101, 231, 234, 222
  db 250, 186, 170, 103, 102, 102, 103, 171, 221, 173, 251, 191, 107, 103, 118, 119, 251, 235, 221, 249, 183, 123, 247, 250, 238
  db 165, 101, 170, 102, 118, 102, 102, 230, 222, 93, 102, 85, 183, 183, 106, 119, 86, 213, 221, 121, 101, 103, 167, 165, 153
  db 169, 169, 170, 255, 123, 187, 187, 251, 238, 238, 238, 255, 103, 102, 170, 118, 255, 239, 221, 126, 251, 251, 167, 169, 157
  db 234, 255, 255, 87, 117, 102, 102, 166, 153, 153, 153, 85, 230, 175, 170, 106, 86, 213, 157, 85, 102, 85, 230, 186, 154
  db 234, 169, 170, 250, 122, 191, 171, 171, 221, 221, 254, 175, 167, 150, 255, 187, 239, 255, 237, 187, 255, 191, 251, 126, 171
  db 234, 157, 170, 86, 105, 86, 166, 166, 222, 157, 85, 218, 231, 171, 87, 102, 151, 149, 93, 101, 86, 85, 86, 101, 183
  db 235, 221, 85, 186, 186, 191, 171, 171, 218, 157, 191, 155, 165, 150, 183, 183, 251, 254, 237, 255, 255, 191, 251, 127, 119
  db 230, 221, 169, 86, 122, 86, 167, 166, 234, 157, 86, 219, 191, 167, 103, 103, 87, 153, 93, 85, 85, 85, 102, 101, 119
  db 234, 221, 253, 255, 191, 255, 167, 235, 170, 157, 190, 155, 85, 247, 251, 183, 247, 255, 237, 255, 255, 187, 251, 127, 103
  db 235, 221, 93, 149, 106, 85, 165, 230, 173, 158, 90, 219, 191, 102, 101, 101, 103, 149, 89, 85, 85, 101, 119, 101, 166
  db 251, 221, 238, 255, 170, 255, 187, 251, 238, 159, 250, 155, 101, 187, 123, 251, 251, 239, 254, 255, 191, 251, 187, 107, 234
  db 86, 157, 85, 149, 106, 85, 101, 118, 85, 153, 123, 149, 122, 119, 118, 118, 102, 149, 86, 85, 86, 102, 85, 250, 191
  db 251, 238, 255, 255, 170, 175, 170, 123, 239, 223, 123, 174, 191, 187, 127, 123, 119, 187, 183, 187, 187, 187, 255, 103, 150
  db 150, 89, 85, 85, 85, 153, 170, 119, 151, 150, 85, 154, 86, 149, 85, 119, 118, 106, 167, 166, 107, 119, 171, 118, 167
  db 246, 190, 255, 255, 191, 175, 191, 119, 235, 235, 171, 234, 250, 255, 254, 103, 171, 222, 234, 173, 86, 102, 150, 118, 166
  db 170, 101, 87, 85, 101, 103, 103, 119, 151, 150, 230, 175, 105, 149, 85, 181, 170, 157, 217, 169, 187, 251, 239, 182, 170
  db 170, 121, 235, 238, 123, 119, 119, 119, 235, 235, 167, 153, 238, 255, 170, 171, 170, 158, 254, 170, 87, 182, 218, 166, 186
  db 170, 122, 151, 153, 182, 183, 183, 119, 151, 150, 230, 223, 154, 149, 181, 182, 189, 239, 95, 169, 230, 126, 213, 170, 186
  db 170, 127, 187, 238, 103, 101, 101, 117, 235, 251, 167, 217, 237, 254, 190, 126, 94, 89, 217, 170, 182, 106, 255, 218, 171
  db 170, 90, 90, 154, 246, 251, 251, 123, 150, 85, 230, 223, 157, 89, 149, 93, 175, 154, 222, 169, 126, 119, 171, 154, 169
  db 170, 170, 155, 234, 119, 118, 118, 182, 175, 255, 167, 217, 221, 238, 255, 173, 90, 171, 239, 186, 158, 122, 150, 153, 154
  db 169, 170, 166, 170, 118, 119, 119, 103, 149, 86, 230, 223, 238, 238, 101, 105, 158, 183, 154, 165, 170, 170, 239, 157, 170
  db 154, 170, 169, 186, 119, 123, 123, 251, 171, 174, 166, 153, 85, 149, 105, 106, 238, 187, 218, 185, 105, 183, 218, 157, 175
  db 170, 229, 170, 126, 119, 86, 86, 87, 166, 174, 234, 159, 238, 254, 254, 234, 90, 85, 169, 109, 171, 122, 213, 157, 235
  db 174, 186, 170, 171, 119, 255, 191, 183, 167, 174, 170, 217, 218, 93, 85, 249, 233, 255, 255, 155, 231, 110, 255, 237, 171
  db 234, 110, 234, 102, 117, 87, 102, 119, 251, 159, 234, 223, 173, 237, 191, 190, 233, 101, 102, 166, 167, 85, 86, 89, 170
  db 90, 169, 155, 250, 127, 183, 102, 118, 86, 153, 170, 217, 221, 90, 85, 159, 254, 106, 119, 231, 251, 191, 255, 254, 171
  db 149, 170, 166, 122, 85, 103, 251, 191, 255, 159, 234, 239, 238, 238, 238, 218, 85, 165, 118, 231, 85, 89, 150, 93, 170
  db 233, 171, 169, 106, 255, 183, 102, 101, 85, 153, 95, 153, 153, 149, 153, 222, 254, 235, 106, 231, 253, 158, 234, 157, 91
  db 254, 229, 170, 106, 86, 102, 187, 123, 255, 223, 151, 222, 157, 169, 175, 234, 149, 229, 173, 235, 157, 157, 250, 157, 150
  db 111, 185, 170, 238, 254, 251, 187, 119, 87, 233, 165, 222, 153, 238, 171, 170, 233, 233, 174, 215, 221, 157, 170, 157, 234
  db 90, 110, 170, 154, 89, 102, 102, 118, 166, 110, 233, 158, 233, 154, 90, 170, 233, 234, 85, 247, 238, 174, 255, 158, 254
  db 150, 175, 175, 187, 251, 119, 119, 103, 250, 94, 238, 153, 174, 234, 155, 170, 169, 250, 253, 183, 170, 106, 87, 213, 175
  db 165, 102, 87, 102, 102, 118, 119, 166, 191, 217, 222, 233, 170, 166, 218, 254, 174, 150, 89, 102, 85, 85, 247, 239, 170
  db 169, 122, 231, 238, 238, 119, 103, 250, 171, 254, 238, 169, 170, 250, 155, 93, 153, 255, 253, 247, 255, 191, 167, 217, 105
  db 170, 122, 167, 153, 153, 118, 166, 191, 170, 153, 153, 173, 170, 109, 234, 175, 234, 151, 89, 182, 170, 106, 167, 218, 93
  db 170, 122, 231, 170, 170, 103, 170, 86, 85, 153, 153, 173, 170, 158, 86, 106, 234, 229, 190, 167, 153, 89, 167, 230, 173
  db 254, 127, 231, 234, 170, 183, 187, 187, 186, 187, 187, 174, 106, 222, 174, 86, 234, 233, 89, 235, 221, 157, 167, 235, 93
  db 94, 85, 231, 234, 169, 119, 119, 183, 126, 119, 183, 175, 170, 238, 238, 191, 250, 234, 153, 214, 157, 153, 231, 234, 173
  db 222, 191, 251, 234, 254, 119, 119, 119, 105, 119, 119, 169, 181, 154, 153, 89, 106, 165, 185, 239, 237, 255, 167, 218, 93
  db 222, 101, 151, 154, 85, 101, 102, 102, 106, 102, 102, 110, 121, 171, 221, 157, 250, 171, 123, 219, 93, 85, 166, 230, 173
  db 239, 122, 231, 214, 253, 191, 255, 251, 239, 239, 187, 94, 122, 183, 154, 153, 171, 181, 183, 235, 221, 255, 167, 235, 93
  db 170, 117, 231, 165, 173, 90, 171, 181, 214, 214, 101, 154, 106, 102, 187, 187, 231, 190, 123, 85, 157, 85, 229, 234, 173
  db 106, 121, 167, 233, 174, 150, 107, 185, 229, 165, 169, 254, 255, 186, 102, 102, 167, 101, 166, 255, 222, 255, 255, 238, 94
  db 122, 186, 167, 238, 173, 165, 91, 122, 169, 169, 170, 90, 85, 105, 255, 174, 246, 127, 103, 85, 157, 85, 85, 85, 150
  db 191, 106, 229, 222, 109, 169, 151, 106, 170, 170, 170, 255, 175, 171, 90, 157, 122, 85, 246, 255, 222, 255, 255, 191, 251
  db 85, 169, 254, 238, 93, 170, 166, 170, 170, 170, 170, 86, 149, 246, 159, 175, 187, 255, 123, 85, 157, 85, 85, 101, 86
  db 255, 175, 95, 85, 153, 170, 170, 170, 170, 170, 234, 255, 186, 106, 153, 86, 103, 149, 182, 255, 222, 255, 255, 187, 255
  db 153, 153, 154, 170, 254, 175, 255, 250, 235, 235, 170, 85, 105, 255, 238, 191, 251, 175, 101, 85, 221, 153, 153, 166, 153
  db 221, 237, 159, 170, 174, 150, 107, 185, 229, 165, 249, 175, 171, 87, 89, 106, 87, 217, 238, 255, 223, 221, 221, 230, 221
  db 217, 89, 217, 238, 174, 165, 91, 122, 169, 169, 106, 149, 246, 187, 170, 90, 230, 218, 221, 85, 213, 221, 157, 166, 153
  db 238, 190, 158, 153, 109, 169, 151, 106, 170, 170, 254, 186, 106, 86, 238, 238, 238, 249, 238, 237, 238, 221, 153, 251, 238
  db 157, 165, 238, 255, 94, 170, 166, 170, 170, 170, 90, 105, 250, 187, 154, 89, 217, 126, 149, 221, 217, 157, 185, 150, 153
  db 238, 123, 105, 85, 153, 170, 170, 170, 170, 170, 175, 235, 126, 101, 170, 254, 238, 101, 255, 157, 233, 153, 190, 255, 237
  db 89, 181, 123, 170, 254, 171, 191, 250, 234, 170, 150, 230, 105, 186, 191, 94, 153, 121, 150, 153, 238, 254, 111, 149, 217
  db 190, 123, 117, 238, 174, 165, 91, 122, 169, 233, 186, 238, 125, 122, 101, 222, 255, 191, 255, 233, 158, 85, 169, 255, 237
  db 85, 182, 126, 154, 109, 169, 151, 106, 170, 170, 105, 222, 169, 127, 186, 223, 85, 85, 149, 237, 221, 170, 106, 149, 157
  db 187, 123, 169, 255, 94, 170, 166, 170, 170, 170, 235, 222, 105, 85, 106, 213, 249, 251, 255, 153, 217, 170, 106, 234, 237
  db 101, 118, 191, 85, 153, 170, 170, 170, 170, 170, 230, 221, 169, 171, 255, 255, 121, 122, 149, 254, 255, 250, 255, 239, 89
  db 239, 126, 150, 233, 254, 170, 175, 186, 170, 186, 254, 238, 170, 166, 154, 153, 121, 86, 170, 102, 150, 86, 85, 217, 254
  db 217, 93, 254, 169, 109, 169, 151, 106, 170, 106, 90, 85, 229, 175, 222, 221, 185, 175, 171, 118, 231, 229, 191, 223, 85
  db 222, 157, 154, 254, 94, 170, 166, 170, 170, 171, 174, 191, 170, 149, 154, 153, 121, 213, 187, 106, 167, 233, 85, 218, 249
  db 157, 157, 250, 86, 153, 170, 170, 170, 170, 230, 239, 87, 250, 191, 254, 255, 186, 171, 102, 170, 231, 255, 238, 223, 125
  db 222, 154, 106, 166, 190, 170, 171, 187, 170, 170, 85, 166, 106, 85, 94, 150, 121, 165, 182, 255, 231, 149, 149, 217, 89
  db 223, 233, 234, 251, 94, 170, 230, 119, 171, 234, 255, 187, 254, 255, 238, 231, 185, 170, 106, 85, 229, 237, 250, 223, 254
  db 149, 233, 170, 89, 153, 170, 250, 118, 183, 170, 85, 86, 90, 85, 89, 230, 121, 169, 250, 255, 255, 153, 101, 149, 85
  db 238, 238, 170, 239, 174, 170, 190, 186, 187, 239, 255, 171, 255, 255, 187, 251, 185, 191, 123, 89, 150, 237, 251, 239, 238
  db 153, 217, 150, 86, 153, 171, 170, 102, 102, 153, 86, 150, 86, 85, 101, 86, 105, 85, 123, 158, 231, 217, 101, 153, 153
  db 255, 234, 165, 254, 170, 183, 170, 118, 103, 222, 167, 166, 250, 191, 170, 250, 191, 191, 86, 154, 230, 254, 238, 239, 255
  db 153, 169, 169, 90, 185, 103, 171, 118, 166, 158, 182, 250, 123, 101, 191, 106, 101, 87, 254, 255, 239, 153, 149, 89, 86
  db 218, 169, 171, 250, 106, 183, 182, 102, 238, 239, 123, 123, 118, 122, 103, 187, 187, 251, 174, 89, 217, 221, 190, 159, 246
  db 170, 233, 171, 106, 185, 123, 107, 186, 158, 85, 102, 182, 119, 122, 123, 102, 118, 85, 153, 217, 218, 157, 85, 150, 190
  db 166, 170, 150, 234, 122, 102, 183, 191, 239, 191, 103, 107, 181, 127, 86, 255, 127, 251, 255, 249, 253, 237, 255, 255, 175
  db 165, 234, 170, 170, 121, 126, 119, 86, 102, 102, 167, 167, 106, 85, 170, 87, 85, 103, 85, 173, 89, 153, 153, 153, 165
  db 169, 234, 158, 171, 191, 94, 119, 171, 119, 119, 166, 166, 250, 191, 170, 247, 255, 183, 187, 219, 189, 239, 217, 217, 105
  db 234, 171, 149, 166, 150, 237, 119, 171, 102, 102, 170, 235, 123, 101, 175, 103, 85, 118, 119, 231, 109, 155, 173, 173, 249
  db 250, 170, 171, 171, 235, 93, 117, 171, 186, 170, 171, 230, 118, 122, 155, 247, 191, 103, 102, 234, 89, 214, 222, 222, 190
  db 182, 218, 234, 234, 250, 173, 187, 171, 190, 238, 235, 175, 181, 127, 150, 102, 101, 247, 191, 234, 253, 255, 238, 238, 174
  db 165, 214, 221, 237, 93, 93, 102, 106, 105, 153, 150, 149, 106, 85, 170, 187, 123, 102, 85, 170, 157, 149, 149, 149, 165
  db 169, 230, 221, 89, 237, 223, 170, 91, 106, 170, 166, 187, 250, 191, 170, 119, 183, 251, 187, 171, 221, 185, 186, 186, 106
  db 170, 251, 222, 238, 94, 217, 173, 151, 171, 170, 170, 102, 123, 101, 251, 119, 102, 101, 101, 246, 223, 105, 102, 102, 246
  db 170, 86, 149, 153, 173, 223, 157, 166, 230, 238, 191, 175, 182, 127, 102, 182, 255, 187, 187, 123, 213, 237, 238, 238, 190
  db 165, 255, 255, 222, 110, 219, 157, 186, 235, 157, 85, 150, 106, 86, 174, 103, 89, 101, 118, 118, 234, 153, 153, 153, 169
  db 174, 86, 149, 157, 109, 150, 237, 127, 251, 237, 191, 191, 250, 187, 175, 247, 223, 175, 123, 187, 239, 185, 187, 187, 191
  db 149, 238, 238, 217, 110, 175, 90, 85, 151, 89, 101, 86, 106, 86, 90, 102, 153, 150, 119, 167, 149, 169, 170, 170, 166
  db 250, 154, 221, 173, 109, 218, 170, 171, 166, 185, 123, 255, 251, 187, 222, 239, 222, 251, 187, 235, 238, 171, 153, 153, 189
  db 165, 173, 218, 221, 90, 239, 238, 234, 255, 127, 123, 86, 101, 86, 158, 213, 157, 86, 149, 217, 149, 250, 255, 191, 170
  db 249, 221, 234, 221, 189, 154, 153, 154, 85, 101, 103, 255, 250, 187, 154, 235, 221, 187, 174, 221, 238, 103, 89, 165, 186
  db 169, 221, 173, 221, 89, 223, 157, 166, 235, 106, 118, 86, 105, 86, 191, 247, 158, 86, 154, 222, 149, 117, 222, 127, 185
  db 250, 238, 238, 159, 189, 218, 153, 255, 251, 253, 127, 191, 250, 187, 86, 166, 217, 171, 191, 218, 238, 107, 154, 86, 190
  db 101, 85, 85, 213, 175, 158, 173, 87, 149, 93, 85, 86, 107, 86, 238, 174, 157, 150, 86, 234, 149, 182, 170, 171, 170
  db 254, 238, 238, 174, 86, 153, 239, 247, 239, 153, 171, 175, 246, 167, 223, 173, 154, 231, 255, 170, 169, 103, 171, 151, 191
  db 149, 221, 221, 153, 187, 186, 90, 102, 213, 233, 171, 214, 107, 250, 219, 173, 191, 166, 89, 169, 255, 167, 182, 187, 90
  db 234, 221, 157, 185, 87, 190, 218, 235, 239, 249, 170, 171, 245, 87, 218, 109, 150, 250, 239, 235, 86, 166, 122, 87, 154
  db 234, 221, 153, 123, 167, 175, 170, 150, 213, 105, 86, 246, 107, 166, 218, 93, 167, 106, 102, 181, 169, 167, 122, 166, 174
  db 235, 157, 185, 119, 182, 102, 245, 187, 239, 173, 167, 106, 245, 187, 154, 153, 183, 251, 187, 127, 171, 187, 127, 186, 175

_intro_block	dd 013131312h, 013131313h, 013131313h, 013131313h
		dd 013131213h, 013131313h, 013131313h, 013131313h
		dd 013121313h, 013131313h, 013131313h, 013131313h
		dd 012131313h, 013131313h, 013131313h, 013131313h
		dd 013131313h, 011121211h, 012121212h, 012121112h
		dd 013131313h, 015151512h, 015141515h, 014151515h
		dd 013131313h, 016161512h, 016161616h, 016161616h
		dd 013131313h, 016161512h, 016161616h, 016161616h
		dd 013131313h, 016161511h, 016161616h, 016161616h
		dd 013131313h, 016161411h, 016161616h, 016161616h
		dd 013131313h, 016161412h, 016161616h, 016161616h
		dd 013131313h, 016161512h, 016161616h, 016161616h
		dd 013131313h, 016161412h, 016161616h, 016161616h
		dd 013131313h, 016161512h, 016161616h, 016161616h
		dd 013131313h, 016161512h, 016161616h, 016161616h
		dd 013131313h, 016161512h, 016161616h, 016161616h
		dd 013131313h, 013131313h, 013131313h, 013131313h
		dd 013131313h, 013131313h, 013131313h, 013131313h
		dd 013131313h, 013131313h, 013131313h, 013131313h
		dd 013131313h, 013131313h, 013131313h, 013131313h
		dd 012121212h, 012111212h, 011121212h, 012121212h
		dd 015151414h, 015151515h, 015151515h, 015151414h
		dd 016161616h, 016161616h, 016161616h, 016161616h
		dd 016161616h, 016161616h, 016161616h, 016161616h
		dd 016161616h, 016161616h, 016161616h, 016161616h
		dd 016161616h, 016161616h, 016161616h, 016161616h
		dd 016161616h, 016161616h, 016161616h, 016161616h
		dd 016161616h, 016161616h, 016161616h, 016161616h
		dd 016161616h, 016161616h, 016161616h, 016161616h
		dd 016161616h, 016161616h, 016161616h, 016161616h
		dd 016161616h, 016161616h, 016161616h, 016161616h
		dd 016161616h, 016161616h, 016161616h, 016161616h
		dd 013131313h, 013131313h, 013131313h, 016131313h
		dd 013131313h, 013131313h, 013131313h, 019161313h
		dd 013131313h, 013131313h, 013131313h, 019191613h
		dd 013131313h, 013131313h, 013131313h, 019191916h
		dd 012121212h, 012121111h, 015121212h, 019191919h
		dd 015151514h, 014151515h, 018151414h, 019191919h
		dd 016161616h, 016161616h, 018151616h, 019191919h
		dd 016161616h, 016161616h, 018151616h, 019191919h
		dd 016161616h, 016161616h, 017151616h, 019191919h
		dd 016161616h, 016161616h, 018151616h, 019191919h
		dd 016161616h, 016161616h, 018141616h, 019191919h
		dd 016161616h, 016161616h, 018151616h, 019191919h
		dd 016161616h, 016161616h, 017151616h, 019191919h
		dd 016161616h, 016161616h, 018151616h, 019191919h
		dd 016161616h, 016161616h, 018151616h, 019191919h
		dd 016161616h, 016161616h, 018151616h, 019191919h
		dd 013131313h, 013131313h, 013131313h, 013131313h
		dd 013131313h, 013131313h, 013131313h, 013131313h
		dd 013131313h, 013131313h, 013131313h, 013131313h
		dd 013131313h, 013131313h, 013131313h, 013131313h
		dd 011111212h, 012111212h, 012121212h, 011121112h
		dd 015151515h, 014151415h, 015151515h, 014151515h
		dd 016161616h, 016161616h, 016161616h, 016161616h
		dd 016161616h, 016161616h, 016161616h, 016161616h
		dd 016161616h, 016161616h, 016161616h, 016161616h
		dd 016161616h, 016161616h, 016161616h, 016161616h
		dd 016161616h, 016161616h, 015151616h, 014141515h
		dd 016161616h, 016161616h, 018151616h, 018181718h
		dd 016161616h, 016161616h, 018151616h, 019191919h
		dd 016161616h, 016161616h, 018151616h, 019191919h
		dd 016161616h, 016161616h, 018141616h, 019191919h
		dd 016161616h, 016161616h, 017141616h, 019191919h
		dd 013131313h, 016161512h, 016161616h, 016161616h
		dd 013131313h, 016161511h, 016161616h, 016161616h
		dd 013131313h, 016161411h, 016161616h, 016161616h
		dd 013131313h, 016161512h, 016161616h, 016161616h
		dd 012121212h, 016161512h, 016161616h, 016161616h
		dd 015141515h, 016161515h, 016161616h, 016161616h
		dd 016161616h, 016161616h, 016161616h, 016161616h
		dd 016161616h, 016161616h, 016161616h, 016161616h
		dd 016161616h, 016161616h, 016161616h, 016161616h
		dd 016161616h, 016161616h, 016161616h, 016161616h
		dd 015151414h, 016161515h, 016161616h, 016161616h
		dd 018181818h, 016161515h, 016161616h, 016161616h
		dd 016191919h, 016161512h, 016161616h, 016161616h
		dd 013161919h, 016161512h, 016161616h, 016161616h
		dd 013131619h, 016161511h, 016161616h, 016161616h
		dd 013131316h, 016161512h, 016161616h, 016161616h
		dd 013131313h, 016161512h, 016161616h, 016161616h
		dd 013131313h, 016161512h, 015141315h, 016161616h
		dd 013131313h, 016161512h, 018161613h, 016161616h
		dd 013131313h, 016161412h, 019161614h, 016161617h
		dd 013131313h, 016161412h, 018191815h, 016161717h
		dd 013131313h, 016161512h, 017171616h, 016171717h
		dd 013131313h, 016161512h, 017161616h, 016171717h
		dd 013131313h, 016161512h, 016161616h, 016161717h
		dd 013131313h, 016161511h, 016161616h, 016161616h
		dd 013131313h, 016161512h, 015141315h, 016161616h
		dd 013131313h, 016161412h, 018161613h, 016161616h
		dd 013131313h, 016161512h, 019161614h, 016161617h
		dd 013131313h, 016161512h, 018191815h, 016161717h
		dd 013131313h, 016161512h, 017171616h, 016171717h
		dd 013131313h, 016161512h, 017161616h, 016171717h
		dd 013131313h, 016161512h, 016161616h, 016161717h
		dd 013131313h, 016161511h, 016161616h, 016161616h
		dd 013131313h, 016161411h, 016161616h, 016161616h
		dd 013131313h, 016161512h, 016161616h, 016161616h
		dd 013131313h, 016161512h, 016161616h, 016161616h
		dd 013131313h, 016161512h, 016161616h, 016161616h
		dd 013131313h, 016161512h, 016161616h, 016161616h
		dd 013131313h, 016161412h, 016161616h, 016161616h
		dd 013131313h, 016161512h, 016161616h, 016161616h
		dd 013131313h, 016161512h, 016161616h, 016161616h
		dd 013131313h, 016161512h, 016161616h, 016161616h
		dd 013131313h, 016161512h, 016161616h, 016161616h
		dd 013131313h, 016161412h, 016161616h, 016161616h
		dd 013131313h, 016161512h, 016161616h, 016161616h
		dd 013131313h, 016161512h, 016161616h, 016161616h
		dd 013131313h, 016161512h, 016161616h, 016161616h
		dd 013131313h, 016161511h, 016161616h, 016161616h
		dd 016161616h, 016161616h, 016161616h, 016161616h
		dd 016161616h, 016161616h, 016161616h, 016161616h
		dd 016161616h, 016161616h, 016161616h, 016161616h
		dd 016161616h, 016161616h, 016161616h, 016161616h
		dd 016161616h, 016161616h, 016161616h, 016161616h
		dd 016161616h, 016161616h, 016161616h, 016161616h
		dd 016161616h, 016161616h, 016161616h, 016161616h
		dd 016161616h, 016161616h, 016161616h, 016161616h
		dd 016161616h, 016161616h, 016161616h, 016161616h
		dd 016161616h, 016161616h, 016161616h, 016161616h
		dd 016161616h, 016161616h, 016161616h, 016161616h
		dd 016161616h, 016161616h, 016161616h, 016161616h
		dd 016161616h, 016161616h, 016161616h, 016161616h
		dd 016161616h, 016161616h, 016161616h, 016161616h
		dd 016161616h, 016161616h, 016161616h, 016161616h
		dd 016161616h, 016161616h, 016161616h, 016161616h
		dd 016161616h, 016161616h, 018141616h, 019191919h
		dd 016161616h, 016161616h, 018141616h, 019191919h
		dd 016161616h, 016161616h, 018141616h, 019191919h
		dd 016161616h, 016161616h, 018151616h, 019191919h
		dd 016161616h, 016161616h, 017141616h, 019191919h
		dd 016161616h, 016161616h, 017151616h, 019191919h
		dd 016161616h, 016161616h, 018151616h, 019191919h
		dd 016161616h, 016161616h, 018151616h, 019191919h
		dd 016161616h, 016161616h, 018141616h, 019191919h
		dd 016161616h, 016161616h, 018141616h, 019191919h
		dd 016161616h, 016161616h, 017141616h, 019191919h
		dd 016161616h, 016161616h, 017151616h, 019191919h
		dd 016161616h, 016161616h, 017151616h, 019191919h
		dd 016161616h, 016161616h, 018151616h, 019191919h
		dd 016161616h, 016161616h, 018151616h, 019191919h
		dd 016161616h, 016161616h, 018151616h, 019191919h
		dd 016161616h, 016161616h, 018151616h, 016191919h
		dd 016161616h, 016161616h, 018151616h, 013161919h
		dd 016161616h, 016161616h, 018151616h, 013131619h
		dd 016161616h, 016161616h, 018151616h, 013131316h
		dd 016161616h, 016161616h, 015151616h, 011121212h
		dd 016161616h, 016161616h, 015151616h, 014151415h
		dd 016161616h, 016161616h, 016161616h, 016161616h
		dd 016161616h, 016161616h, 016161616h, 016161616h
		dd 016161616h, 016161616h, 016161616h, 016161616h
		dd 016161616h, 016161616h, 016161616h, 016161616h
		dd 016161616h, 016161616h, 015141616h, 015141515h
		dd 016161616h, 016161616h, 017141616h, 018181818h
		dd 016161616h, 016161616h, 018151616h, 019191919h
		dd 016161616h, 016161616h, 018151616h, 019191919h
		dd 016161616h, 016161616h, 018151616h, 019191919h
		dd 016161616h, 016161616h, 018151616h, 019191919h
		dd 013131313h, 013131313h, 013131313h, 013131313h
		dd 013131313h, 013131313h, 013131313h, 013131313h
		dd 013131313h, 013131313h, 013131313h, 013131313h
		dd 013131313h, 013131313h, 013131313h, 013131313h
		dd 012121211h, 011121212h, 012121211h, 012121212h
		dd 015151515h, 015141415h, 015151515h, 015151515h
		dd 016161616h, 016161616h, 016161616h, 016161616h
		dd 016161616h, 016161616h, 016161616h, 016161616h
		dd 016161616h, 016161616h, 016161616h, 016161616h
		dd 016161616h, 016161616h, 016161616h, 016161616h
		dd 015151515h, 015141414h, 014151514h, 015151514h
		dd 018181818h, 018181717h, 017181818h, 018181818h
		dd 019191919h, 019191919h, 019191919h, 019191919h
		dd 019191919h, 019191919h, 019191919h, 019191919h
		dd 019191919h, 019191919h, 019191919h, 019191919h
		dd 019191919h, 019191919h, 019191919h, 019191919h
		dd 016161616h, 016161616h, 018151616h, 019191919h
		dd 013151616h, 016161615h, 018151616h, 019191919h
		dd 015131616h, 016161816h, 018151616h, 019191919h
		dd 016151616h, 016171917h, 018141616h, 019191919h
		dd 018161616h, 017171819h, 018141616h, 019191919h
		dd 016161616h, 017171717h, 017151617h, 019191919h
		dd 016161616h, 017171716h, 017151617h, 019191919h
		dd 016161616h, 017171616h, 018151616h, 019191919h
		dd 016161616h, 016161616h, 018151616h, 019191919h
		dd 013151616h, 016161615h, 018151616h, 019191919h
		dd 015131616h, 016161816h, 018151616h, 019191919h
		dd 016151616h, 016171917h, 017151616h, 019191919h
		dd 018161616h, 017171819h, 017151616h, 019191919h
		dd 016161616h, 017171717h, 017141617h, 019191919h
		dd 016161616h, 017171716h, 018141617h, 019191919h
		dd 016161616h, 017171616h, 018151616h, 019191919h
		dd 013131313h, 016161511h, 016161616h, 016161616h
		dd 013131313h, 016161511h, 016161616h, 016161616h
		dd 013131313h, 016161512h, 016161616h, 016161616h
		dd 013131313h, 016161512h, 016161616h, 016161616h
		dd 013131313h, 016161512h, 016161616h, 016161616h
		dd 013131313h, 016161512h, 016161616h, 016161616h
		dd 013131313h, 016161412h, 016161616h, 016161616h
		dd 013131313h, 016161412h, 016161616h, 016161616h
		dd 013131313h, 016161412h, 016161616h, 016161616h
		dd 013131313h, 016161412h, 016161616h, 016161616h
		dd 013131313h, 014151511h, 015151514h, 015151515h
		dd 012131313h, 018181815h, 018181818h, 017171818h
		dd 016121313h, 019191918h, 019191919h, 019191919h
		dd 018161313h, 019191919h, 019191919h, 019191919h
		dd 019191613h, 019191919h, 019191919h, 019191919h
		dd 019191816h, 019191919h, 019191919h, 019191919h
		dd 016161616h, 016161616h, 016161616h, 016161616h
		dd 016161616h, 016161616h, 016161616h, 016161616h
		dd 016161616h, 016161616h, 016161616h, 016161616h
		dd 016161616h, 016161616h, 016161616h, 016161616h
		dd 016161616h, 016161616h, 016161616h, 016161616h
		dd 016161616h, 016161616h, 016161616h, 016161616h
		dd 016161616h, 016161616h, 016161616h, 016161616h
		dd 016161616h, 016161616h, 016161616h, 016161616h
		dd 016161616h, 016161616h, 016161616h, 016161616h
		dd 016161616h, 016161616h, 016161616h, 016161616h
		dd 015141414h, 015151515h, 014151515h, 015151514h
		dd 018181817h, 018181818h, 018181817h, 018171818h
		dd 019191919h, 019191919h, 019191919h, 019191919h
		dd 019191919h, 019191919h, 019191919h, 019191919h
		dd 019191919h, 019191919h, 019191919h, 019191919h
		dd 019191919h, 019191919h, 019191919h, 019191919h
		dd 016161616h, 016161616h, 018151616h, 019191919h
		dd 016161616h, 016161616h, 018151616h, 019191919h
		dd 016161616h, 016161616h, 018151616h, 019191919h
		dd 016161616h, 016161616h, 018151616h, 019191919h
		dd 016161616h, 016161616h, 018151616h, 019191919h
		dd 016161616h, 016161616h, 018151616h, 019191919h
		dd 016161616h, 016161616h, 018151616h, 019191919h
		dd 016161616h, 016161616h, 018151616h, 019191919h
		dd 016161616h, 016161616h, 018151616h, 019191919h
		dd 016161616h, 016161616h, 018151616h, 019191919h
		dd 015151515h, 014151515h, 018141515h, 019191919h
		dd 018181818h, 018181818h, 017171818h, 019191919h
		dd 019191919h, 019191919h, 019191919h, 019191919h
		dd 019191919h, 019191919h, 019191919h, 019191919h
		dd 019191919h, 019191919h, 019191919h, 019191919h
		dd 019191919h, 019191919h, 019191919h, 019191919h
		dd 016161616h, 016161616h, 017141616h, 016191919h
		dd 016161616h, 016161616h, 017151616h, 013161919h
		dd 016161616h, 016161616h, 018151616h, 013131619h
		dd 016161616h, 016161616h, 018151616h, 013131316h
		dd 016161616h, 016161616h, 015151616h, 011111212h
		dd 016161616h, 016161616h, 015151616h, 014151515h
		dd 016161616h, 016161616h, 016161616h, 016161616h
		dd 016161616h, 016161616h, 016161616h, 016161616h
		dd 016161616h, 016161616h, 016161616h, 016161616h
		dd 016161616h, 016161616h, 016161616h, 016161616h
		dd 015141515h, 014151515h, 014141414h, 015151515h
		dd 017171818h, 017171818h, 018181817h, 018181718h
		dd 019191919h, 019191919h, 019191919h, 019191919h
		dd 019191919h, 019191919h, 019191919h, 019191919h
		dd 019191919h, 019191919h, 019191919h, 019191919h
		dd 019191919h, 019191919h, 019191919h, 019191919h
		dd 013131313h, 013131313h, 013131313h, 016131313h
		dd 013131313h, 013131313h, 013131313h, 019161313h
		dd 013131313h, 013131313h, 013131313h, 019191613h
		dd 013131313h, 013131313h, 013131313h, 019191916h
		dd 012121212h, 011121212h, 015121212h, 019191919h
		dd 015151414h, 015141515h, 018151515h, 019191919h
		dd 016161616h, 016161616h, 018141616h, 019191919h
		dd 016161616h, 016161616h, 017141616h, 019191919h
		dd 016161616h, 016161616h, 017151616h, 019191919h
		dd 016161616h, 016161616h, 018151616h, 019191919h
		dd 015151515h, 015151515h, 018141414h, 019191919h
		dd 018181818h, 018181817h, 017171717h, 019191919h
		dd 019191919h, 019191919h, 019191919h, 019191919h
		dd 019191919h, 019191919h, 019191919h, 019191919h
		dd 019191919h, 019191919h, 019191919h, 019191919h
		dd 019191919h, 019191919h, 019191919h, 019191919h
		dd 016161616h, 016161616h, 018151616h, 019191919h
		dd 016161616h, 016161616h, 018151616h, 019191919h
		dd 017181616h, 017171717h, 019161717h, 01A1A1A1Ah
		dd 016171616h, 016161616h, 018151616h, 019191919h
		dd 016171616h, 016161616h, 018151616h, 019191919h
		dd 016171616h, 015151416h, 017141515h, 018181818h
		dd 016171616h, 016161516h, 018151616h, 019191919h
		dd 016171616h, 016161516h, 018151616h, 019191919h
		dd 016171616h, 016161516h, 018151616h, 019191919h
		dd 016171616h, 016161516h, 018151616h, 01919191Ah
		dd 015161515h, 014151415h, 018151514h, 01919191Ah
		dd 018191818h, 018181718h, 01A181718h, 0191A191Bh
		dd 0191A1919h, 019191819h, 019191919h, 0191A1A1Ah
		dd 0191A1919h, 019191819h, 019191919h, 0191A1A19h
		dd 0191A1919h, 019191819h, 019191919h, 01A1A1919h
		dd 0191A1919h, 019191819h, 019191919h, 01A1A1A19h
		dd 00h, 00h, 00h, 00h
		dd 00h, 00h, 00h, 00h
		dd 00h, 00h, 00h, 01A000000h
		dd 00h, 00h, 00h, 013151A00h
		dd 00h, 00h, 00h, 013131318h
		dd 00h, 00h, 016000000h, 013131313h
		dd 00h, 00h, 013151A00h, 013131313h
		dd 00h, 00h, 01213151Ah, 013131313h
		dd 00h, 01A000000h, 012121316h, 014131312h
		dd 00h, 0151A0000h, 012111112h, 016151312h
		dd 00h, 013150000h, 012111012h, 016161513h
		dd 00h, 012131600h, 013121210h, 016161615h
		dd 00h, 010121318h, 015131211h, 016161616h
		dd 01A000000h, 011111213h, 016151312h, 017161616h
		dd 015000000h, 012121213h, 016161513h, 017161716h
		dd 0131A0000h, 013131313h, 016161514h, 017171616h
		dd 00h, 015171A00h, 013131314h, 013131313h
		dd 015171A00h, 013131314h, 013131313h, 013131313h
		dd 013131314h, 013131313h, 013131313h, 013131313h
		dd 013131313h, 013131313h, 013131313h, 013131313h
		dd 013131313h, 013131313h, 012121212h, 012121211h
		dd 013131313h, 015141212h, 014151515h, 015151514h
		dd 014121213h, 016161515h, 016161616h, 016161616h
		dd 016151412h, 016161616h, 016161616h, 016161616h
		dd 016161615h, 016161616h, 016161616h, 016161616h
		dd 016161616h, 016161616h, 016161616h, 016161616h
		dd 016161616h, 016161616h, 016161616h, 016161616h
		dd 016161616h, 016161616h, 016161616h, 015151616h
		dd 016161616h, 016161616h, 016161616h, 018171516h
		dd 016161616h, 016161616h, 016161616h, 019191815h
		dd 016161616h, 016161616h, 015161616h, 019191917h
		dd 016161618h, 016161616h, 016161616h, 019191918h
		dd 013131313h, 013131313h, 013131313h, 013131313h
		dd 013131313h, 013131313h, 013131313h, 013131313h
		dd 013131313h, 013131313h, 013131313h, 013131313h
		dd 013131313h, 013131313h, 013131313h, 013131313h
		dd 011111212h, 012121211h, 012121212h, 011121212h
		dd 015141414h, 015151515h, 015151515h, 015151415h
		dd 016161616h, 016161616h, 016161616h, 016161616h
		dd 016161616h, 016161616h, 016161616h, 016161616h
		dd 016161616h, 016161616h, 016161616h, 016161616h
		dd 016161616h, 016161616h, 016161616h, 016161616h
		dd 015151616h, 015151515h, 016151515h, 016161616h
		dd 018181817h, 018181818h, 017171818h, 016151516h
		dd 019191919h, 019191919h, 019191919h, 015171819h
		dd 019191919h, 019191919h, 019191919h, 017181819h
		dd 019191919h, 019191919h, 019191919h, 017171818h
		dd 019191919h, 019191919h, 018191919h, 016171718h
		dd 013131313h, 013131313h, 013131313h, 013131313h
		dd 013131313h, 013131313h, 013131313h, 013131313h
		dd 013131313h, 013131313h, 013131313h, 013131313h
		dd 013131313h, 013131313h, 013131313h, 013131313h
		dd 012121212h, 012121212h, 012121212h, 012121112h
		dd 015151515h, 014141515h, 015151515h, 015151515h
		dd 016161616h, 016161616h, 016161616h, 016161616h
		dd 016161616h, 016161616h, 016161616h, 016161616h
		dd 016161616h, 016161616h, 016161616h, 016161616h
		dd 016161616h, 016161616h, 016161616h, 016161616h
		dd 015151515h, 015151515h, 015151515h, 016161616h
		dd 018181818h, 018181818h, 017171818h, 016161515h
		dd 019191919h, 019191919h, 019191919h, 015161718h
		dd 019191919h, 019191919h, 019191919h, 016181819h
		dd 019191919h, 019191919h, 019191919h, 017171818h
		dd 019191919h, 019191919h, 018191919h, 016171718h
		dd 013131313h, 014131313h, 01A1715h, 00h
		dd 013131313h, 013131313h, 014131313h, 01A1715h
		dd 013131313h, 013131313h, 013131313h, 014131313h
		dd 013131313h, 013131313h, 013131313h, 013131313h
		dd 011121212h, 012121212h, 013131312h, 013131313h
		dd 015141415h, 015151514h, 012121315h, 013131313h
		dd 016161616h, 016161616h, 014161616h, 013131313h
		dd 016161616h, 016161616h, 016161616h, 012141515h
		dd 016161616h, 016161616h, 016161616h, 015151616h
		dd 016161616h, 016161616h, 016161616h, 016161616h
		dd 016161616h, 016161616h, 016161616h, 016161616h
		dd 016161616h, 016161616h, 016161616h, 016161616h
		dd 016161616h, 016161616h, 016161616h, 016161616h
		dd 016161615h, 016161616h, 016161616h, 016161616h
		dd 016161515h, 016161616h, 016161617h, 016161616h
		dd 016151416h, 016161616h, 016161516h, 016161616h
		dd 00h, 00h, 00h, 00h
		dd 00h, 00h, 00h, 00h
		dd 01Ah, 00h, 00h, 00h
		dd 01A1513h, 00h, 00h, 00h
		dd 018131313h, 00h, 00h, 00h
		dd 014131313h, 016h, 00h, 00h
		dd 014141313h, 01A1514h, 00h, 00h
		dd 014141413h, 01A151515h, 00h, 00h
		dd 015141313h, 016161515h, 01Ah, 00h
		dd 015151415h, 016161615h, 01A17h, 00h
		dd 015151616h, 017161616h, 01A1717h, 00h
		dd 015161616h, 017171616h, 0181817h, 00h
		dd 016161616h, 017171715h, 019181818h, 00h
		dd 016161616h, 018171516h, 019191818h, 01Ah
		dd 016161616h, 018161616h, 019191918h, 019h
		dd 016161616h, 017151616h, 019191919h, 01A19h
		dd 013140000h, 012131313h, 016161615h, 019181616h
		dd 013131A00h, 015131313h, 016161616h, 015161716h
		dd 013131700h, 015121313h, 017161616h, 016161616h
		dd 013131500h, 016141313h, 016161616h, 016161615h
		dd 013131400h, 016151213h, 016161616h, 016161616h
		dd 01313131Ah, 016151213h, 016161616h, 016161616h
		dd 013131317h, 016161413h, 016161616h, 016161616h
		dd 013131315h, 016161512h, 016161616h, 016161616h
		dd 013131314h, 016161512h, 016161616h, 016161616h
		dd 013131313h, 016161512h, 016161616h, 016161616h
		dd 013131313h, 016161512h, 016161616h, 016161616h
		dd 013131313h, 016161512h, 016161616h, 016161616h
		dd 013131313h, 016161512h, 016161616h, 016161616h
		dd 013131313h, 016161512h, 016161616h, 016161616h
		dd 013131313h, 016161512h, 016161616h, 016161616h
		dd 013131313h, 016161512h, 016161616h, 016161616h
		dd 016161519h, 016161616h, 017151616h, 019191919h
		dd 015151417h, 016161616h, 018141616h, 019191919h
		dd 016161515h, 016161616h, 018151616h, 019191919h
		dd 016161615h, 016161616h, 018141616h, 019191919h
		dd 016161616h, 016161616h, 018141616h, 019191919h
		dd 016161616h, 016161616h, 017151616h, 019191919h
		dd 016161616h, 016161616h, 017151616h, 019191919h
		dd 016161616h, 016161616h, 017151616h, 019191919h
		dd 016161616h, 016161616h, 018151616h, 019191919h
		dd 016161616h, 016161616h, 018151616h, 019191919h
		dd 016161616h, 016161616h, 017141616h, 019191919h
		dd 016161616h, 016161616h, 018151616h, 019191919h
		dd 016161616h, 016161616h, 018151616h, 019191919h
		dd 016161616h, 016161616h, 017151616h, 019191919h
		dd 016161616h, 016161616h, 018151616h, 019191919h
		dd 016161616h, 016161616h, 018151616h, 019191919h
		dd 01A19h, 00h, 0181A0000h, 016161717h
		dd 01Ah, 00h, 00h, 016161619h
		dd 00h, 00h, 00h, 015161900h
		dd 00h, 00h, 00h, 015180000h
		dd 00h, 00h, 00h, 015000000h
		dd 00h, 00h, 00h, 018000000h
		dd 00h, 00h, 00h, 01A000000h
		dd 00h, 00h, 00h, 00h
		dd 00h, 00h, 00h, 00h
		dd 00h, 00h, 00h, 00h
		dd 00h, 00h, 00h, 00h
		dd 00h, 00h, 00h, 00h
		dd 00h, 00h, 00h, 00h
		dd 00h, 00h, 00h, 00h
		dd 00h, 00h, 00h, 00h
		dd 00h, 00h, 00h, 00h
		dd 00h, 00h, 0181A0000h, 016161717h
		dd 00h, 00h, 00h, 016161619h
		dd 00h, 00h, 00h, 015161900h
		dd 00h, 00h, 00h, 015180000h
		dd 00h, 00h, 00h, 015000000h
		dd 00h, 00h, 00h, 018000000h
		dd 00h, 00h, 00h, 01A000000h
		dd 00h, 00h, 00h, 00h
		dd 00h, 00h, 00h, 00h
		dd 00h, 00h, 00h, 00h
		dd 00h, 00h, 00h, 00h
		dd 00h, 00h, 00h, 00h
		dd 00h, 00h, 00h, 00h
		dd 00h, 00h, 00h, 00h
		dd 00h, 00h, 00h, 00h
		dd 00h, 00h, 00h, 00h
		dd 015131516h, 016161616h, 016161616h, 016161616h
		dd 014141515h, 016161616h, 016161616h, 016161616h
		dd 013141415h, 016161615h, 016161616h, 016161616h
		dd 013131414h, 016161614h, 016161616h, 016161616h
		dd 013131314h, 016161613h, 016161616h, 016161616h
		dd 013131313h, 016161612h, 016161616h, 016161616h
		dd 013131313h, 016161613h, 016161616h, 016161616h
		dd 013131313h, 016161512h, 016161616h, 016161616h
		dd 013131313h, 016161512h, 016161616h, 016161616h
		dd 013131313h, 016161512h, 016161616h, 016161616h
		dd 013131313h, 016161412h, 016161616h, 016161616h
		dd 013131313h, 016161512h, 016161616h, 016161616h
		dd 013131313h, 016161512h, 016161616h, 017161616h
		dd 013131313h, 016161511h, 016161616h, 016161616h
		dd 013131313h, 016161510h, 016161616h, 016161616h
		dd 013131313h, 016161511h, 016161616h, 016161616h
		dd 016161616h, 015161616h, 019191918h, 01919h
		dd 016161616h, 016161616h, 019191916h, 01A1919h
		dd 016161616h, 016161616h, 019191815h, 01A1919h
		dd 016161616h, 016161616h, 019191616h, 0191919h
		dd 016161616h, 016161616h, 019191516h, 0191919h
		dd 016161616h, 016161616h, 019181516h, 01A191919h
		dd 016161616h, 016161616h, 019171616h, 01A191919h
		dd 016161616h, 016161616h, 019171616h, 01A191919h
		dd 016161616h, 016161616h, 019161616h, 019191919h
		dd 016161616h, 016161616h, 019151616h, 019191919h
		dd 016161616h, 016161616h, 018151616h, 019191919h
		dd 016161617h, 016161717h, 018151616h, 019191919h
		dd 016161718h, 016161516h, 017151616h, 019191919h
		dd 016151515h, 016161616h, 018141616h, 019191919h
		dd 016161616h, 016161616h, 018141616h, 019191919h
		dd 016161616h, 016161616h, 018151616h, 019191919h
		dd 00h, 00h, 00h, 00h
		dd 00h, 00h, 00h, 00h
		dd 00h, 00h, 00h, 00h
		dd 00h, 00h, 00h, 00h
		dd 00h, 00h, 00h, 00h
		dd 00h, 00h, 00h, 00h
		dd 00h, 00h, 00h, 00h
		dd 00h, 00h, 00h, 00h
		dd 00h, 00h, 00h, 00h
		dd 00h, 00h, 00h, 01A000000h
		dd 00h, 00h, 00h, 018000000h
		dd 00h, 00h, 00h, 015000000h
		dd 00h, 00h, 00h, 014190000h
		dd 00h, 00h, 00h, 013141A00h
		dd 00h, 00h, 00h, 013131419h
		dd 00h, 00h, 015181A00h, 013131313h
		dd 013131313h, 016161512h, 016161616h, 016161616h
		dd 013131313h, 016161512h, 016161616h, 016161616h
		dd 013131313h, 016161512h, 016161616h, 016161616h
		dd 013131313h, 016161512h, 015171716h, 016161616h
		dd 013131313h, 017161512h, 015141616h, 016161616h
		dd 013131313h, 016161512h, 016161615h, 016161616h
		dd 013131313h, 015161512h, 016161616h, 016161616h
		dd 014131313h, 016161513h, 016161616h, 016161617h
		dd 013131315h, 016161411h, 016161616h, 016161516h
		dd 014131313h, 016161513h, 016161616h, 016161616h
		dd 012111313h, 018171713h, 016151518h, 016161616h
		dd 012131313h, 015151514h, 017181816h, 016161717h
		dd 012131313h, 016161615h, 015151515h, 015151415h
		dd 014121313h, 016161616h, 016161616h, 016161515h
		dd 015121313h, 016161616h, 016161616h, 016161616h
		dd 016141313h, 016161616h, 016161616h, 016161616h
		dd 016161616h, 016161616h, 018151616h, 019191919h
		dd 016161616h, 016161616h, 018151616h, 019191919h
		dd 016161616h, 016161616h, 018151616h, 019191919h
		dd 016161616h, 016161616h, 018151616h, 019191919h
		dd 016161616h, 016161616h, 018151616h, 019191919h
		dd 016161616h, 016161616h, 018151616h, 019191919h
		dd 016161616h, 016161616h, 018151616h, 019191919h
		dd 016161616h, 016161616h, 018151616h, 019191919h
		dd 016161616h, 016161616h, 018161616h, 01A191919h
		dd 016161616h, 016161616h, 019171616h, 01A191919h
		dd 016161616h, 016161616h, 019181616h, 01A191919h
		dd 016161616h, 016161616h, 019181516h, 0191919h
		dd 016161616h, 016161616h, 019191716h, 0191919h
		dd 016161616h, 016161616h, 019191815h, 01A1919h
		dd 016161616h, 016161616h, 019191917h, 01919h
		dd 016161616h, 015161616h, 019191918h, 01919h
		dd 00h, 00h, 00h, 00h
		dd 00h, 00h, 00h, 00h
		dd 00h, 00h, 00h, 00h
		dd 00h, 00h, 00h, 00h
		dd 00h, 00h, 00h, 00h
		dd 00h, 00h, 00h, 00h
		dd 00h, 00h, 00h, 00h
		dd 00h, 00h, 00h, 00h
		dd 00h, 00h, 00h, 00h
		dd 00h, 00h, 00h, 01A000000h
		dd 00h, 00h, 00h, 018000000h
		dd 00h, 00h, 00h, 015000000h
		dd 00h, 00h, 00h, 013190000h
		dd 00h, 00h, 00h, 013131A00h
		dd 00h, 00h, 00h, 013131319h
		dd 00h, 00h, 015181A00h, 013131313h
		dd 013131313h, 016161512h, 016161616h, 016161616h
		dd 013131313h, 016161412h, 016161616h, 016161616h
		dd 013131313h, 016161511h, 016161616h, 016161616h
		dd 013131313h, 016161512h, 016161616h, 016161616h
		dd 013131313h, 016161512h, 016161616h, 016161616h
		dd 013131313h, 016161512h, 016161616h, 016161616h
		dd 013131313h, 016161512h, 016161616h, 016161616h
		dd 013131313h, 016161512h, 016161616h, 016161616h
		dd 013131313h, 016161512h, 016161616h, 016161616h
		dd 013131313h, 016161512h, 016161616h, 016161616h
		dd 013131313h, 016161613h, 016161616h, 016161616h
		dd 012131313h, 016161614h, 016161616h, 016161616h
		dd 012131313h, 016161615h, 016161616h, 016161616h
		dd 014121313h, 016161616h, 016161616h, 016161616h
		dd 015101313h, 016161616h, 016161616h, 016161616h
		dd 016141313h, 016161616h, 016161616h, 016161616h
		dd 016161616h, 016161616h, 018151616h, 019191919h
		dd 016161616h, 016161616h, 018151616h, 019191919h
		dd 016161616h, 016161616h, 017151616h, 019191919h
		dd 016161616h, 016161616h, 018151616h, 019191919h
		dd 016161616h, 016161616h, 018141616h, 019191919h
		dd 016161616h, 016161616h, 018141616h, 019191919h
		dd 016161616h, 016161616h, 018151616h, 019191919h
		dd 016161616h, 016161616h, 018151616h, 019191919h
		dd 016161616h, 016161616h, 019171516h, 019191919h
		dd 016161616h, 016161616h, 019171516h, 019191919h
		dd 016161616h, 016161616h, 019181516h, 01A191919h
		dd 016161616h, 016161616h, 019191516h, 01A191919h
		dd 016161616h, 016161616h, 019191616h, 0191919h
		dd 016161616h, 016161616h, 019191715h, 0191919h
		dd 016171817h, 016161616h, 019191915h, 01919h
		dd 015161516h, 016171617h, 0191A1917h, 01919h
		dd 013131313h, 013131313h, 013131313h, 013131313h
		dd 013131313h, 013131313h, 013131313h, 012131313h
		dd 013131313h, 013131313h, 013131313h, 014121213h
		dd 013131313h, 013131313h, 012121313h, 016151412h
		dd 012121212h, 012121212h, 015141312h, 016161615h
		dd 015151515h, 015151515h, 016161615h, 016161616h
		dd 016161616h, 016161616h, 016161616h, 016161616h
		dd 016161616h, 016161616h, 016161616h, 016161616h
		dd 016161616h, 016161616h, 016161616h, 016161616h
		dd 016161616h, 016161616h, 016161616h, 016161616h
		dd 015151515h, 015151515h, 015151515h, 015151515h
		dd 018181818h, 018181818h, 018181818h, 018181818h
		dd 019191919h, 019191919h, 019191919h, 019191919h
		dd 019191919h, 019191919h, 019191919h, 019191919h
		dd 019191919h, 019191919h, 019191919h, 019191919h
		dd 019191919h, 019191919h, 019191919h, 019191919h
		dd 016151212h, 016161616h, 016161616h, 016161616h
		dd 016161513h, 016161616h, 016161616h, 016161616h
		dd 016161615h, 016161616h, 016161616h, 016161616h
		dd 016161616h, 016161616h, 016161616h, 016161616h
		dd 016161616h, 016161616h, 016161616h, 016161616h
		dd 016161616h, 016161616h, 016161616h, 016161616h
		dd 016161616h, 016161616h, 016161616h, 016161616h
		dd 016161616h, 016161616h, 016161616h, 015161616h
		dd 016161616h, 016161616h, 016161616h, 018171516h
		dd 016161616h, 016161616h, 016151616h, 019191817h
		dd 015151515h, 015151515h, 019191817h, 019191919h
		dd 018181818h, 019191918h, 019191919h, 019191919h
		dd 019191919h, 019191919h, 019191919h, 019191919h
		dd 019191919h, 019191919h, 019191919h, 019191919h
		dd 019191919h, 019191919h, 019191919h, 01A19h
		dd 019191919h, 019191919h, 01A1A1Ah, 00h
		dd 016161616h, 017161616h, 019191919h, 01A19h
		dd 016161616h, 018161616h, 019191919h, 019h
		dd 016161616h, 019181516h, 019191919h, 00h
		dd 016161616h, 019191815h, 01A191919h, 00h
		dd 015161616h, 019191918h, 0191919h, 00h
		dd 018151616h, 019191919h, 01919h, 00h
		dd 019181616h, 019191919h, 019h, 00h
		dd 019191818h, 019191919h, 00h, 00h
		dd 019191919h, 0191919h, 00h, 00h
		dd 019191919h, 01919h, 00h, 00h
		dd 019191919h, 019h, 00h, 00h
		dd 01A191919h, 00h, 00h, 00h
		dd 01919h, 00h, 00h, 00h
		dd 01Ah, 00h, 00h, 00h
		dd 00h, 00h, 00h, 00h
		dd 00h, 00h, 00h, 00h
		dd 013131313h, 013131313h, 013131313h, 013131313h
		dd 013131313h, 013131313h, 013131313h, 013131313h
		dd 013131313h, 013131313h, 013131313h, 013121313h
		dd 013131313h, 013131313h, 013131313h, 016151312h
		dd 012121212h, 012121212h, 014131212h, 016161615h
		dd 015151515h, 015151515h, 016161615h, 016161616h
		dd 016161616h, 016161616h, 016161616h, 016161616h
		dd 016161616h, 016161616h, 016161616h, 016161616h
		dd 016161616h, 016161616h, 016161616h, 016161616h
		dd 016161616h, 016161616h, 016161616h, 016161616h
		dd 014141415h, 015151515h, 015151515h, 016161615h
		dd 017181818h, 018181717h, 017171818h, 016151515h
		dd 019191919h, 019191919h, 019191919h, 015161819h
		dd 019191919h, 019191919h, 019191919h, 016181819h
		dd 019191919h, 019191919h, 019191919h, 017171818h
		dd 019191919h, 019191919h, 018191919h, 016171718h
		dd 016151213h, 016161616h, 016161616h, 016161616h
		dd 016161412h, 016161616h, 016161616h, 016161616h
		dd 016161615h, 016161616h, 016161616h, 016161616h
		dd 016161616h, 016161616h, 016161616h, 016161616h
		dd 016161616h, 016161616h, 016161616h, 016161616h
		dd 016161616h, 016161616h, 016161616h, 016161616h
		dd 016161616h, 016161616h, 016161616h, 016161616h
		dd 016161616h, 016161616h, 016161616h, 016161616h
		dd 016161616h, 016161616h, 016161616h, 015161616h
		dd 016161616h, 016161616h, 016161616h, 016161616h
		dd 016161616h, 016161616h, 016161616h, 016161616h
		dd 016161616h, 016161616h, 016161616h, 016161616h
		dd 016161616h, 016161616h, 016161616h, 016161616h
		dd 016161615h, 016161616h, 016161616h, 016161616h
		dd 016161516h, 016161616h, 016161616h, 016161616h
		dd 016151516h, 016161616h, 016161616h, 016161616h
		dd 015161616h, 017161615h, 01A1A1A1Ah, 01Ah
		dd 016161616h, 017141616h, 01A191818h, 01Ah
		dd 016161616h, 019181516h, 018181819h, 00h
		dd 016161616h, 019191715h, 01A181919h, 00h
		dd 015161616h, 019191918h, 0191919h, 00h
		dd 018151616h, 019191919h, 01919h, 00h
		dd 019181516h, 019191919h, 019h, 00h
		dd 019191815h, 019191919h, 00h, 00h
		dd 019191715h, 019191919h, 00h, 00h
		dd 019181516h, 019191919h, 019h, 00h
		dd 018151616h, 019191919h, 01919h, 00h
		dd 015161616h, 019191918h, 0191919h, 00h
		dd 016161616h, 019191815h, 01A191919h, 00h
		dd 016161616h, 019181516h, 019191919h, 00h
		dd 016161616h, 018151616h, 019191919h, 019h
		dd 016161616h, 016151616h, 019191918h, 019h
		dd 016161616h, 015161616h, 019191918h, 013161919h
		dd 016161616h, 016161616h, 019191917h, 013131619h
		dd 016161616h, 017161616h, 019191816h, 013131316h
		dd 016161616h, 016161616h, 016181717h, 013131313h
		dd 016161616h, 017161616h, 012151517h, 012101112h
		dd 016161616h, 017171616h, 015151515h, 015151515h
		dd 016161616h, 015171816h, 016151615h, 016161616h
		dd 016161616h, 016141618h, 016161616h, 016161616h
		dd 017161616h, 016161415h, 016161616h, 016161616h
		dd 015161616h, 016161616h, 016161616h, 016161616h
		dd 016161616h, 016161616h, 015151616h, 014151515h
		dd 016161616h, 016161616h, 018151616h, 018181818h
		dd 016161616h, 016161616h, 018141616h, 019191919h
		dd 016161616h, 016161616h, 017141616h, 019191919h
		dd 016161616h, 016161616h, 017151616h, 019191919h
		dd 016161616h, 016161616h, 018151616h, 019191919h
		dd 013131313h, 016161512h, 016151616h, 016161616h
		dd 013131313h, 016161412h, 016141616h, 016161616h
		dd 013131313h, 016161412h, 016121716h, 016161616h
		dd 013131313h, 016161412h, 016141616h, 016161616h
		dd 013131313h, 016161412h, 016151716h, 017161616h
		dd 013131313h, 016161412h, 015141916h, 017161616h
		dd 013131313h, 016161411h, 015111916h, 016161616h
		dd 013131313h, 016161511h, 015121716h, 017161616h
		dd 013131313h, 016161512h, 014131817h, 017161616h
		dd 013131313h, 016161512h, 015141917h, 017161616h
		dd 013131313h, 015151512h, 014141717h, 017151515h
		dd 012131313h, 018181815h, 01718191Ah, 01A181818h
		dd 016121313h, 019191919h, 01813191Ch, 01B191919h
		dd 01A161313h, 019191919h, 018191A1Bh, 01A191919h
		dd 0191A1613h, 01A191919h, 018171A1Bh, 01A191919h
		dd 019191916h, 01B1A1919h, 018171A1Fh, 01B1A1919h
		dd 016161617h, 015161616h, 018151616h, 016191919h
		dd 016161417h, 014171616h, 018151616h, 013161919h
		dd 016161318h, 013181616h, 018151615h, 013131619h
		dd 016161119h, 0141A1716h, 018151615h, 013131316h
		dd 016161418h, 014191716h, 015151616h, 012101212h
		dd 016161417h, 014181616h, 015151615h, 015151515h
		dd 016161218h, 010181616h, 016161614h, 016161616h
		dd 016151418h, 014191616h, 016161514h, 016161616h
		dd 016151417h, 0151A1616h, 016161614h, 016161616h
		dd 016151517h, 015191716h, 016161613h, 016161616h
		dd 015141316h, 014171615h, 015151412h, 015151415h
		dd 018171718h, 0191A1818h, 018181718h, 017171818h
		dd 01918171Ah, 0181B1919h, 019191718h, 019191919h
		dd 01918121Bh, 0191B1A19h, 019191717h, 019191919h
		dd 01917161Ah, 0191B1A1Ah, 019181719h, 019191919h
		dd 019181B1Fh, 01B1F1B1Ah, 018171917h, 019191919h
		dd 00h, 00h, 0181A0000h, 016161717h
		dd 00h, 00h, 00h, 016161619h
		dd 00h, 00h, 00h, 015161900h
		dd 00h, 00h, 00h, 015180000h
		dd 00h, 00h, 00h, 015000000h
		dd 00h, 00h, 00h, 018000000h
		dd 00h, 00h, 00h, 01A000000h
		dd 00h, 00h, 00h, 00h
		dd 00h, 00h, 00h, 00h
		dd 00h, 00h, 00h, 00h
		dd 00h, 00h, 00h, 00h
		dd 00h, 00h, 00h, 00h
		dd 00h, 00h, 00h, 00h
		dd 00h, 00h, 00h, 00h
		dd 00h, 00h, 00h, 00h
		dd 00h, 00h, 00h, 00h
		dd 016131516h, 016161616h, 016161616h, 016161616h
		dd 014141515h, 016161616h, 016161616h, 016161616h
		dd 013141415h, 016161615h, 016161616h, 016161616h
		dd 012131414h, 016161615h, 016161616h, 016161616h
		dd 013131314h, 016161614h, 016161616h, 016161616h
		dd 013131313h, 016161514h, 016161616h, 016161616h
		dd 013131313h, 016161513h, 016161616h, 016161616h
		dd 013131313h, 016161512h, 016171616h, 016161616h
		dd 013131313h, 016161512h, 015161616h, 016161616h
		dd 013131313h, 016161512h, 016161616h, 018161616h
		dd 013131313h, 016161512h, 016161616h, 016161616h
		dd 013131313h, 016161511h, 016161616h, 016161616h
		dd 013131313h, 016161412h, 016161616h, 016161616h
		dd 013131313h, 016161412h, 016161616h, 016161616h
		dd 013131313h, 016161512h, 016161616h, 016161616h
		dd 013131313h, 016161512h, 016161616h, 016161616h
		dd 016161616h, 015161616h, 019191917h, 01919h
		dd 016161616h, 016161616h, 019191815h, 01919h
		dd 016161616h, 016161616h, 019191716h, 0191919h
		dd 016161616h, 016161616h, 019191516h, 0191919h
		dd 016161616h, 016161616h, 019181516h, 01A191919h
		dd 016161616h, 016161616h, 019171616h, 01A191919h
		dd 016161616h, 016161616h, 018161616h, 019191919h
		dd 016161616h, 016161616h, 018151616h, 019191919h
		dd 016161617h, 016161616h, 018141616h, 019191919h
		dd 016161517h, 016161616h, 018141616h, 019191919h
		dd 016161412h, 016161616h, 018151616h, 019191919h
		dd 016161616h, 016161616h, 018141616h, 019191919h
		dd 016161616h, 016161616h, 018151616h, 019191919h
		dd 016161616h, 016161616h, 018151616h, 019191919h
		dd 016161616h, 016161616h, 018151616h, 019191919h
		dd 016161616h, 016161616h, 017141616h, 019191919h


_intro_title_y  dw 8320
  dw 8320
  dw 8640
  dw 8960
  dw 9280
  dw 9280
  dw 9600
  dw 9920
  dw 10240
  dw 10560
  dw 10560
  dw 10880
  dw 11200
  dw 11200
  dw 11520
  dw 11840
  dw 11840
  dw 12160
  dw 12480
  dw 12480
  dw 12800
  dw 12800
  dw 13120
  dw 13120
  dw 13440
  dw 13440
  dw 13760
  dw 13760
  dw 14080
  dw 14080
  dw 14080
  dw 14080
  dw 14400
  dw 14400
  dw 14400
  dw 14400
  dw 14400
  dw 14400
  dw 14400
  dw 14400
  dw 14400
  dw 14400
  dw 14400
  dw 14400
  dw 14400
  dw 14400
  dw 14400
  dw 14400
  dw 14080
  dw 14080
  dw 14080
  dw 13760
  dw 13760
  dw 13760
  dw 13440
  dw 13440
  dw 13120
  dw 13120
  dw 12800
  dw 12800
  dw 12480
  dw 12160
  dw 12160
  dw 11840
  dw 11520
  dw 11520
  dw 11200
  dw 10880
  dw 10880
  dw 10560
  dw 10240
  dw 9920
  dw 9920
  dw 9600
  dw 9280
  dw 8960
  dw 8640
  dw 8640
  dw 8320
  dw 8000
  dw 7680
  dw 7680
  dw 7360
  dw 7040
  dw 6720
  dw 6400
  dw 6400
  dw 6080
  dw 5760
  dw 5440
  dw 5440
  dw 5120
  dw 4800
  dw 4800
  dw 4480
  dw 4160
  dw 4160
  dw 3840
  dw 3520
  dw 3520
  dw 3200
  dw 3200
  dw 2880
  dw 2880
  dw 2560
  dw 2560
  dw 2560
  dw 2240
  dw 2240
  dw 2240
  dw 1920
  dw 1920
  dw 1920
  dw 1920
  dw 1920
  dw 1920
  dw 1920
  dw 1920
  dw 1920
  dw 1920
  dw 1920
  dw 1920
  dw 1920
  dw 1920
  dw 1920
  dw 1920
  dw 2240
  dw 2240
  dw 2240
  dw 2240
  dw 2560
  dw 2560
  dw 2880
  dw 2880
  dw 3200
  dw 3200
  dw 3520
  dw 3520
  dw 3840
  dw 3840
  dw 4160
  dw 4480
  dw 4480
  dw 4800
  dw 5120
  dw 5120
  dw 5440
  dw 5760
  dw 5760
  dw 6080
  dw 6400
  dw 6720
  dw 7040
  dw 7040
  dw 7360
  dw 7680
  dw 8000
  dw -1

		  ;               B                          E                          D                          L                          A                          M

_intro_title	db 0, 0, 0, 0, 0, 1, 4,11,11,11,22,23,24, 0, 1, 4,11,11,11,17, 0, 0, 0, 1, 4,11,11,11,22,23,24, 0, 1, 3, 0, 0, 0, 0, 0, 0, 0, 1, 4,11,11,11,22,23,24, 0,19,20,21,23,24, 0, 0, 0, 0, 0, 0, 0, 0, 0
		db 0, 0, 0, 0, 0, 7, 9, 0, 0, 0,28,29,30, 0, 7, 9, 0, 0, 0, 0, 0, 0, 0, 7, 9, 0, 0, 0,28,29,30, 0, 7, 9, 0, 0, 0, 0, 0, 0, 0, 7, 9, 0, 0, 0,28,29,30, 0,25,26,27,29,43,22,23,24, 0, 0, 0, 0, 0, 0
		db 0, 0, 0, 0, 0, 7, 9, 0, 0, 0, 0, 7, 9, 0, 7, 9, 0, 0, 0, 0, 0, 0, 0, 7, 9, 0, 0, 0, 0, 7, 9, 0, 7, 9, 0, 0, 0, 0, 0, 0, 0, 7, 9, 0, 0, 0, 0, 7, 9, 0, 7, 9, 0, 7, 9,28,29,30, 0, 0, 0, 0, 0, 0
		db 0, 0, 0, 0, 0, 7, 9, 0, 0, 0,31,32,33, 0, 7, 9, 0, 0, 0, 0, 0, 0, 0, 7, 9, 0, 0, 0, 0, 7, 9, 0, 7, 9, 0, 0, 0, 0, 0, 0, 0, 7, 9, 0, 0, 0, 0, 7, 9, 0, 7, 9, 0, 7, 9, 0, 7, 9, 0, 0, 0, 0, 0, 0
		db 0, 0, 0, 0, 0, 7,10,11,11,11,40,41,42, 0, 7,10,11,11,11,11,17, 0, 0, 7, 9, 0, 0, 0, 0, 7, 9, 0, 7, 9, 0, 0, 0, 0, 0, 0, 0, 7,10,11,11,11,11, 5, 9, 0, 7, 9, 0, 7, 9, 0, 6,12, 0, 0, 0, 0, 0, 0
		db 0, 0, 0, 0, 0, 7, 9, 0, 0, 0,46,47,48, 0, 7, 9, 0, 0, 0, 0, 0, 0, 0, 7, 9, 0, 0, 0, 0, 7, 9, 0, 7, 9, 0, 0, 0, 0, 0, 0, 0, 7, 9, 0, 0, 0, 0, 7, 9, 0, 7, 9, 0, 7, 9, 0, 7, 9, 0, 0, 0, 0, 0, 0
		db 0, 0, 0, 0, 0, 7, 9, 0, 0, 0, 0, 7, 9, 0, 7, 9, 0, 0, 0, 0, 0, 0, 0, 7, 9, 0, 0, 0, 0, 7, 9, 0, 7, 9, 0, 0, 0, 0, 0, 0, 0, 7, 9, 0, 0, 0, 0, 7, 9, 0, 7, 9, 0, 7, 9, 0, 7, 9, 0, 0, 0, 0, 0, 0
		db 0, 0, 0, 0, 0, 7, 9, 0, 0, 0,31,32,33, 0, 7, 9, 0, 0, 0, 0, 0, 0, 0, 7, 9, 0, 0, 0,31,32,33, 0, 7, 9, 0, 0, 0, 0, 0, 0, 0, 7, 9, 0, 0, 0, 0, 7, 9, 0, 7, 9, 0, 7, 9, 0, 7, 9, 0, 0, 0, 0, 0, 0
		db 0, 0, 0, 0, 0,44,45,11,11,11,37,38,39, 0,13,16,11,11,11,11,11,17, 0,13,16,11,11,11,37,38,39, 0,13,16,11,11,11,11,11,17, 0,13,15, 0, 0, 0, 0,13,15, 0,13,15, 0,13,15, 0,13,18, 0, 0, 0, 0, 0, 0

_intro_title_off	dw 0000h
_intro_title_ptr	dw 0000h

_intro_title_yptr	dw 0000h



;---- Intro.

intro:
  call intro_logon
  call intro_main
  call intro_logoff
  ret



;---- Intro_Logon.

intro_logon:

  mov es, _intro_seg
  xor si, si
  xor edi, edi
  mov di, 2

  mov dx, 100
intro_logon_yloop:

  mov cx, 25
intro_logon_xloop:
  mov ah, cs: _intro_back[si]
  mov al, ah
  and al, 3
  ror ah, 2
  mov es: [di], al
  mov al, ah
  and al, 3
  ror ah, 2
  mov es: [di+1], al
  mov al, ah
  and al, 3
  ror ah, 2
  mov es: [di+2], al
  mov al, ah
  and al, 3
  ror ah, 2
  mov es: [di+3], al
  add dword ptr es: [di], 19191919h
  inc si
  add di, 4
  loop intro_logon_xloop

  add di, 2
  dec dx
  jnz intro_logon_yloop

    ;  Sort out masks and shadows.

  mov ds, _sprite_seg
  mov es, _graph_seg
  xor bx, bx
  mov cx, 16*16*6*8
intro_logon_maskloop:
  mov al, byte ptr _intro_block[bx]
  mov dx, 00FFh
  cmp al, 0
  je intro_logon_maskok
  mov dx, 0100h
intro_logon_maskok:
  mov [bx+32000], dl
  mov [bx+48000], dh
  inc bx
  loop intro_logon_maskloop

  ret



;---- Intro_Main.

intro_main:
;  mov _timer_proc, offset cs: intro_timer

    ;  Wait for escape to be released.

intro_esc:

  call intro_timer			;

  cmp _KBD_ESC, 0
  jne intro_esc

    ;  Intro loop.

intro_loop:

  call intro_timer			;

  cmp _KBD_ESC, 0
  jne intro_exit

  cmp _KBD_SPACE, 0
  je intro_loop

intro_end:
  mov _timer_proc, offset timer_null
  xor ax, ax
  ret

intro_exit:
  mov _timer_proc, offset timer_null
  mov ax, -1
  ret



;---- Intro_Logoff.

intro_logoff:
  pushf
  popf
  ret



;---- Intro_Timer.

intro_timer:
  nop
  nop

  push ds
  push es
  push eax
  push ecx
  push dx
  push ebx
  push si
  push di

    ;  Blit on background.

  mov ds, _intro_seg
  mov es, _scr_seg
  mov si, 2
  mov di, 10

  mov dx, 100
intro_yback:
  push si
  push di

  mov cx, 25
intro_xback:
  mov eax, [si]
  mov es: [di], eax
  mov es: [di+100], eax
  mov es: [di+200], eax
  mov es: [di+32000], eax
  mov es: [di+32100], eax
  mov es: [di+32200], eax
  mov [si-1], eax
  add si, 4
  add di, 4
  loop intro_xback

  pop di
  pop si
  mov al, [si-1]
  mov [si+99], al
  add di, 320
  add si, 102

  dec dx
  jnz intro_yback

    ;  Big text.

  mov ds, _sprite_seg
  mov bx, _intro_title_ptr
  and bx, 63
  mov dh, 9
  mov di, _intro_title_yptr	;28*320+4
  mov di, _intro_title_y[di]
  add di, 4
  sub di, _intro_title_off

intro_ytitle:

  push bx

  mov cx, 20
intro_xtitle:

  mov al, _intro_title[bx]
  cmp al, 0
  je intro_nextblock

    ;  Is this a block which has a mask?

  cmp al, 19
  jae intro_notsquare

    ;  Draw square block.

  push di
  push bx
  mov bh, al
  xor bl, bl
  dec bh
  mov dl, 16
intro_square:
  mov eax, _intro_block[bx]
  mov es: [di], eax
  mov eax, _intro_block[bx+4]
  mov es: [di+4], eax
  mov eax, _intro_block[bx+8]
  mov es: [di+8], eax
  mov eax, _intro_block[bx+12]
  mov es: [di+12], eax
  add bx, 16
  add di, 320
  dec dl
  jnz intro_square
  pop bx
  pop di

    ;  Square shadow.

  mov eax, 01010101h

  add es: [di+320* 8+16], eax
  add es: [di+320* 9+16], eax
  add es: [di+320*10+16], eax
  add es: [di+320*11+16], eax
  add es: [di+320* 8+20], eax
  add es: [di+320* 9+20], eax
  add es: [di+320*10+20], eax
  add es: [di+320*11+20], eax

  add es: [di+320*12+16], eax
  add es: [di+320*13+16], eax
  add es: [di+320*14+16], eax
  add es: [di+320*15+16], eax
  add es: [di+320*12+20], eax
  add es: [di+320*13+20], eax
  add es: [di+320*14+20], eax
  add es: [di+320*15+20], eax

  add es: [di+320*16+16], eax
  add es: [di+320*17+16], eax
  add es: [di+320*18+16], eax
  add es: [di+320*19+16], eax
  add es: [di+320*16+20], eax
  add es: [di+320*17+20], eax
  add es: [di+320*18+20], eax
  add es: [di+320*19+20], eax

  add es: [di+320*20+16], eax
  add es: [di+320*21+16], eax
  add es: [di+320*22+16], eax
  add es: [di+320*23+16], eax
  add es: [di+320*20+20], eax
  add es: [di+320*21+20], eax
  add es: [di+320*22+20], eax
  add es: [di+320*23+20], eax

  add es: [di+320*16+ 8], eax
  add es: [di+320*17+ 8], eax
  add es: [di+320*18+ 8], eax
  add es: [di+320*19+ 8], eax
  add es: [di+320*16+12], eax
  add es: [di+320*17+12], eax
  add es: [di+320*18+12], eax
  add es: [di+320*19+12], eax

  add es: [di+320*20+ 8], eax
  add es: [di+320*21+ 8], eax
  add es: [di+320*22+ 8], eax
  add es: [di+320*23+ 8], eax
  add es: [di+320*20+12], eax
  add es: [di+320*21+12], eax
  add es: [di+320*22+12], eax
  add es: [di+320*23+12], eax

  jmp intro_nextblock

intro_notsquare:

    ;  Unsquare block.

  push di
  push bx
  mov bh, al
  xor bl, bl
  dec bh
  mov dl, 16
intro_nonsquare:
  mov eax, [bx+48000]
  add es: [di+4+320*4+321*4], eax
  mov eax, [bx+32000]
  and es: [di], eax
  mov eax, _intro_block[bx]
  xor es: [di], eax

  mov eax, [bx+48004]
  add es: [di+8+320*4+321*4], eax
  mov eax, [bx+32004]
  and es: [di+4], eax
  mov eax, _intro_block[bx+4]
  xor es: [di+4], eax

  mov eax, [bx+48008]
  add es: [di+12+320*4+321*4], eax
  mov eax, [bx+32008]
  and es: [di+8], eax
  mov eax, _intro_block[bx+8]
  xor es: [di+8], eax

  mov eax, [bx+48012]
  add es: [di+16+320*4+321*4], eax
  mov eax, [bx+32012]
  and es: [di+12], eax
  mov eax, _intro_block[bx+12]
  xor es: [di+12], eax

  add bx, 16
  add di, 320
  dec dl
  jnz intro_nonsquare
  pop bx
  pop di

intro_nextblock:
  mov ax, bx
  and ax, -64
  inc bx
  add di, 16
  and bx, 63
  or bx, ax
  loop intro_xtitle

  pop bx
  add bx, 64
  add di, 320*15
  dec dh
  jnz intro_ytitle

  add _intro_title_off, 2
  test _intro_title_off, -16
  jz intro_nomove
  inc _intro_title_ptr
  and _intro_title_off, 15
  and _intro_title_ptr, 63
intro_nomove:

  mov di, _intro_title_yptr
  add di, 2
  cmp _intro_title_y[di], -1
  jne intro_titleyok
  xor di, di
intro_titleyok:
  and di, 511
  mov _intro_title_yptr, di

    ; Clear lines down edge.

  xor eax, eax
  xor di, di
  mov cx, 200
intro_border:
  mov es: [di], eax
  mov es: [di+4], eax
  mov es: [di+8], ax
  mov es: [di+310], eax
  mov es: [di+314], eax
  mov es: [di+318], ax
  add di, 320
  loop intro_border

  call update

  pop di
  pop si
  pop ebx
  pop dx
  pop ecx
  pop eax
  pop es
  pop ds

  ret



;---- GAME --------------------------------------------------------------------;


_levelno	db 00h
_score		dd 0000h

_player_x	db 00h
_player_y	db 00h
_player_off	dw 0000h

_corner_x	db 20
_corner_y	db 12
_corner_tx	db 00h
_corner_ty	db 00h
_corner_off	dw (20)+64*(12)

_gameover	db 00h
_playerok	db 00h
_leveldone	db 00h
_timeout	db 00h
_pause		db 00h

_game_pal	db 256 dup (00h, 00h, 00h)

_sprite_table	dd 01010100h,01010101h,01010101h,01010101h	;  Space.
		dd 0B0A0908h,0F0E0D0Ch,0B0A0908h,0F0E0D0Ch	;  Earth.
		dd 40404040h,40404040H,40404040h,40404040h	;  Diamond.
		dd 4B4B4B4Bh,4F4E4D4Ch,4F4E4D4Ch,4F4E4D4Ch	;  Newdia.
		dd 10101010h,10101010h,10101010h,10101010h	;  Bat.
		dd 18181818h,18181818h,18181818h,18181818h	;  Spirit.
		dd 30313233h,34353637h,30313233h,34353637h	;  Rock.
		dd 20202020h,20202020h,6E665E56h,6F675F57h	;  Wall.
		dd 23222120h,27262524h,23222120h,27262524h	;  Magic.
		dd 04030201h,04030201h,04030201h,04030201h	;  Bang.
		dd 2E2E2F2Fh,2C2C2D2Dh,2A2A2B2Bh,28282929h	;  Mould.
		dd 38383838h,38383838h,38383838h,38383838h	;  Solid.
		dd 06060606h,07070707h,06060606h,07070707h	;  Door.
		dd 3B3A3938h,3F3E3D3Ch,3B3A3938h,3F3E3D3Ch	;  RSolid.
		dd 06060606h,07070707h,06060606h,07070707h	;  Start.
		dd 50505050h,50505050h,50505050h,50505050h	;  Man.

		;    A    B    C    D    E    F    G    H.
		;    I    J    K    L    M    N    O    P.
_level_startx_	db   2,   4,   3,  39,   1,  30,  37,   1
		db   8,  14,  27,  15,  24,  17,  49,  37

_level_starty_	db   5,  11,   4,  33,   1,  33,  30,   2
		db  13,  21,  40,  15,   1,  12,   5,  10

_level_width_	db  35,  58,  44,  41,  33,  64,  64,  20
		db  51,  38,  64,  32,  43,  26, 207,  42

_level_height_	db  28,  28,  40,  35,  21,  64,  64,  12
		db  36,  31,  64,  31,  30,  28,  64,  56

_level_minx_	db   0,   0,   0,   0,   0,   0,   0,   0
		db   0,   0,   0,   0,   0,   0,   0,  22

_level_miny_	db   0,   0,   0,   0,   0,   0,   0,   0
		db   0,   0,   0,   0,   0,   0,   0,   8

_level_time_	db 180, 150, 210, 120, 120, 240, 240,  10
		db 150, 240,  -1, 200, 150, 120, 240, 240

_level_dias_	db  20,  36,  36,  20,   6,  24,  18,   5
		db  80,  90,  50,   9,  60,  40,  76,  33

_level_points_	db  13,  15,  18,  35,  55,  17,  25,  32
		db   5,   7, 179,  21,   8,  10,   7,  79


_level_startx	db 2
_level_starty	db 5
_level_width	db 35
_level_height	db 28
_level_minx	db 00h
_level_miny	db 00h
_level_time	db 20
_level_dias	db 20
_level_points	db 157

		db 64 dup (00h)
_level		db 64*64 dup (00h)
_level_flags	db 64*64 dup (00h)
		db 64 dup (00h)


;---- Game.

game:
  call game_logon
  call game_main
  call game_logoff
  ret



;---- Game_Logon.

game_logon:

    ;  Randomize sozzle buffer.

  xor bx, bx
game_logon_makesozzle:
  mov cs: _game_sozzle_buf[bx], bl
  inc bx
  cmp bx, 240
  jne game_logon_makesozzle

  xor si, si
  xor bx, bx
game_logon_shuffle:
  in al, 40h
  add ah, ah
  xor ah, al
  sub ah, cs: _game_sozzle_buf[bx]
  cmp ah, 240
  jae game_logon_noshuffle
  mov bl, ah
  mov al, cs: _game_sozzle_buf[si]
  xchg al, cs: _game_sozzle_buf[bx]
  mov cs: _game_sozzle_buf[si], al
game_logon_noshuffle:
  inc si
  cmp si, 240
  jne game_logon_shuffle

    ;  Sort out sprite masks.

  mov ds, _sprite_seg
  xor si, si
  mov cx, 32000
game_logon_maskloop:
  mov al, [si]
  cmp al, 0
  mov al, -1
  je game_logon_maskok
  mov al, 0
game_logon_maskok:
  mov [si+32000], al
  inc si
  loop game_logon_maskloop

    ;  Set up game variables.

  mov _score, 0
  mov _gameover, 0
  ret



;---- Game_Logoff.

game_logoff:
  ret



;---- Game_Main.

game_main:
  mov _timer_proc, offset cs: game_start

game_loop:
  cmp _KBD_ESC, 0
  jne game_end

  cmp _gameover, 0
  je game_loop

game_end:

  mov _timer_proc, offset timer_null
  ret



;---- GAME TIMER PROCEDURES.


_game_sozzle_buf	db 240 dup (00h)
_game_sozzle_frame	db 00h
_game_sozzle_block	db 0D0h



;---- Game_Start.

;  The start of the game loop.

game_start:
  nop
  nop
  mov _game_sozzle_frame, 0
  mov _timer_proc, offset cs: game_start_proc

    ;  Set player data.
  push ax
  push bx

  mov _timeout, 0
  mov _playerok, 1
  mov _leveldone, 0

  mov bl, _levelno
  xor bh, bh

  mov al, _level_startx_[bx]
  mov _level_startx, al
  mov al, _level_starty_[bx]
  mov _level_starty, al
  mov al, _level_width_[bx]
  mov _level_width, al
  mov al, _level_height_[bx]
  mov _level_height, al
  mov al, _level_minx_[bx]
  mov _level_minx, al
  mov al, _level_miny_[bx]
  mov _level_miny, al
  mov al, _level_time_[bx]
  mov _level_time, al
  mov al, _level_dias_[bx]
  mov _level_dias, al
  mov al, _level_points_[bx]
  mov _level_points, al

  mov al, _level_startx
  mov ah, _level_starty
  mov _player_x, al
  mov _player_y, ah
  mov bl, ah
  xor bh, bh
  xor ah, ah
  shl bx, 6
  or ax, bx
  mov _player_off, ax

  mov _corner_x, 20
  mov _corner_y, 12
  mov _corner_off, 20+64*12

  mov al, _player_x
  mov ah, _player_y
  sub al, 9
  sub ah, 5
  mov _corner_tx, al
  mov _corner_ty, ah

  pop bx
  pop ax

    ;  Copy level into buffer.
  push es
  push ds
  push ax
  push ecx
  push esi
  push edi
  cld
  mov ds, _level_seg
  mov es, _code_seg
  xor esi, esi
  xor edi, edi
  xor al, al
  mov ah, _levelno
  shl ah, 4
  mov si, ax
  mov di, offset _level
  xor ecx, ecx
  mov cx, 64*64/4
  rep movsd
  pop edi
  pop esi
  pop ecx
  pop ax
  pop ds
  pop es

game_start_proc:
  nop
  nop

  call game_sozzleframe

  call game_status

  cmp _KBD_RSHIFT, 0
  je game_start_nomap
  call game_map
game_start_nomap:

  call update

  add _game_sozzle_frame, 5
  cmp _game_sozzle_frame, 240
  jna game_start_ok
  mov _game_sozzle_frame, 255
  mov _timer_proc, offset cs: game_play
game_start_ok:
  ret



;---- Game_Play.

;  Moves the game on a frame.

_game_play_time	db 00h
_game_play_bar	db 00h

game_play:
  nop
  nop

  inc _game_play_time
  cmp _game_play_time, 18
  jb game_play_timeok
  mov _game_play_time, 0

  cmp _level_time, 0
  je game_play_timeout
  dec _level_time
  jmp game_play_timeok

game_play_timeout:
  mov _timeout, 1

game_play_timeok:

  call game_move

  call game_frame

    ;  If last diamond just collected, flash white.

  cmp _leveldone, 1
  je game_play_noflash
  cmp _level_dias, 0
  jne game_play_noflash

  push es
  push edi
  push eax
  push ecx
  mov es, _scr_seg
  xor ecx, ecx
  xor edi, edi
  mov cx, 16000
  mov eax, 0F0F0F0Fh
  rep stosd
  mov _leveldone, 1
  pop ecx
  pop eax
  pop edi
  pop es

game_play_noflash:

    ;  Print status or message.

  inc _game_play_bar

  cmp _playerok, 0
  jne game_play_status

  cmp _KBD_SPACE, 0
  je game_play_lifeoverok
  mov _timer_proc, offset cs: game_finish
game_play_lifeoverok:

  test _game_play_bar, 32
  jz game_play_status

  cmp _timeout, 0
  je game_play_dead
  call game_timeout
  jmp game_play_nostatus

game_play_dead:
  call game_gameover
  jmp game_play_nostatus

game_play_status:
  call game_status

game_play_nostatus:

  cmp _KBD_RSHIFT, 0
  je game_play_nomap
  call game_map
game_play_nomap:

  call update

  ret



;---- Game_Finish.

_game_finish_pause	db 00h

game_finish:
  nop
  nop
  mov _game_sozzle_frame, 240
  mov _timer_proc, offset cs: game_finish_proc
  mov _game_finish_pause, 18*2

game_finish_proc:
  nop
  nop

  call game_sozzleframe

  call game_status

  call update

  sub _game_sozzle_frame, 5
  cmp _game_sozzle_frame, 4
  ja game_finish_ok

  mov _game_sozzle_frame, 0
  mov _timer_proc, offset cs: game_finish_pause

game_finish_ok:
  ret

game_finish_pause:
  nop
  nop

  call game_sozzleframe

  call game_status

  call update

  dec _game_finish_pause
  jnz game_finish_pause_ok
  mov _timer_proc, offset cs: game_start

game_finish_pause_ok:
  ret



;---- GAME MISC ROUTINNES.

game_move:
  cmp _timeout, 0
  mov _playerok, 0
  je game_move_timeok
  ret

game_move_timeok:

  push ds
  push es
  push eax
  push ecx
  push dx
  push si
  push edi

    ;  Clear moved flags.

  mov es, _code_seg
  xor edi, edi
  xor ecx, ecx
  mov di, offset cs: _level_flags
  mov cx, 64*64/4
  xor eax, eax
  rep stosd

  mov _playerok, 0

    ;  Move each character in turn.

  mov ds, _code_seg
  xor si, si
  mov dh, 64
game_move_y:

  mov dl, 64
game_move_x:

  cmp _level_flags[si], 0
  jne game_move_no

  mov al, _level[si]

  cmp al, 10h
  jb move_space_
  cmp al, 20h
  jb move_earth_
  cmp al, 30h
  jb move_diamond_
  cmp al, 40h
  jb move_newdia_
  cmp al, 50h
  jb move_bat_
  cmp al, 60h
  jb move_spirit_
  cmp al, 70h
  jb move_rock_
  cmp al, 80h
  jb move_wall_
  cmp al, 90h
  jb move_magic_
  cmp al, 0A0h
  jb move_bang_
  cmp al, 0B0h
  jb move_mould_
  cmp al, 0C0h
  jb move_solid_
  cmp al, 0D0h
  jb move_door_
  cmp al, 0E0h
  jb move_rsolid_
  cmp al, 0F0h
  jb move_start_
  jmp move_man_

game_move_ok:
game_move_no:

  inc si
  dec dl
  jnz game_move_x

  dec dh
  jnz game_move_y

  pop edi
  pop si
  pop dx
  pop ecx
  pop eax
  pop es
  pop ds
  ret



;---- Individual move routines.

;  Branches.

move_space_:	jmp move_space
move_earth_:	jmp move_earth
move_diamond_:	jmp move_diamond
move_newdia_:	jmp move_newdia
move_bat_:	jmp move_bat
move_spirit_:	jmp move_spirit
move_rock_:	jmp move_rock
move_wall_:	jmp move_wall
move_magic_:	jmp move_magic
move_bang_:	jmp move_bang
move_mould_:	jmp move_mould
move_solid_:	jmp move_solid
move_door_:	jmp move_door
move_rsolid_:	jmp move_rsolid
move_start_:	jmp move_start
move_man_:	jmp move_man


;  These characters don't seem to do much.

move_space:
move_earth:
move_wall:
move_solid:
move_rsolid:
  jmp game_move_ok



;  Move door.

move_door:
  push ax
  cmp _leveldone, 0
  je move_door_no
  inc al
  and al, 0Fh
  or al, 0C0h
  mov _level[si], al
move_door_no:
  pop ax
  jmp game_move_ok



;  Characters not yet programmed.

move_magic:
move_mould:
  jmp game_move_ok



;  Move newdia.

move_newdia:
  mov _level[si], 20h
  jmp game_move_ok

  push ax

  mov al, _level[si]
  inc al
  and al, 3
  jz move_newdia_diamond
  or al, 30h
  mov _level[si], al
  pop ax
  jmp game_move_ok

move_newdia_diamond:
  mov _level[si], 20h
  pop ax
  jmp game_move_ok




;  Move bang.

move_bang:
  push ax
  mov al, _level[si]

  cmp al, 9Ch
  jne move_bang_notman
  mov _playerok, 1
move_bang_notman:

  mov ah, al
  inc al
  and ah, 0FCh
  and al, 3
  jz move_bang_gone
  or al, ah
  mov _level[si], al
  pop ax
  jmp game_move_ok

move_bang_gone:
  cmp ah, 9Ch
  je move_bang_man

  mov byte ptr _level[si], 0
  pop ax
  jmp game_move_ok

move_bang_man:
  mov _level[si], 0F0h
  pop ax
  jmp game_move_ok



;  Move start.

move_start:
  mov _playerok, 1
  mov _game_play_bar, 0

  push ax
  mov al, _level[si]
  inc al
  and al, 0Fh
  or al, 0E0h
  cmp al, 0E0h
  jne move_start_ok
  mov al, 9Ch
move_start_ok:
  mov _level[si], al

  pop ax
  jmp game_move_ok



;  Move fallers.

move_diamond:
move_rock:
  push ax
  push si
  push di

    ;  Is there a gap below?
  test _level[si+64], 0F0h
  jnz move_rock_nofall

  lea di, [si+64]
  jmp move_rock_move

move_rock_nofall:

  mov ah, _level[si+64]
  and ah, 0F0h
  cmp ah, 20h
  je move_rock_slip
  cmp ah, 60h
  je move_rock_slip
  cmp ah, 70h
  je move_rock_slip
  cmp ah, 0A0h
  je move_rock_slip
  jmp move_rock_noslip

move_rock_slip:

  test _level[si+1], 0F0h
  jnz move_rock_noright
  test _level[si+65], 0F0h
  jnz move_rock_noright
  lea di, [si+1]
  jmp move_rock_move

move_rock_noright:

  test _level[si-1], 0F0h
  jnz move_rock_noleft
  test _level[si+63], 0F0h
  jnz move_rock_noleft
  lea di, [si-1]
  jmp move_rock_move

move_rock_noleft:

move_rock_noslip:

  test _level[si], 8
  jnz move_rock_falling
  and _level[si], 0F7h
  pop di
  pop si
  pop ax
  jmp game_move_ok

move_rock_falling:
  and _level[si], 0F7h
  sub si, 64
  jmp move_rock_hits

move_rock_move:

  cmp si, di
  je move_rock_end
  or _level[si], 8
  test al, 8
  jz move_rock_end
  or al, 8
  mov _level[si], 0
  mov _level[di], al
  mov _level_flags[di], 8

    ;  Check for hits if falling (not slipping).
  sub di, 64
  cmp di, si
  jne move_rock_end

move_rock_hits:

  mov ah, _level[si+128]
  and ah, 0F0h
  cmp ah, 40h
  je move_rock_hitbat
  cmp ah, 50h
  je move_rock_hitspirit
  cmp ah, 0F0h
  je move_rock_hitman

move_rock_end:

  pop di
  pop si
  pop ax
  jmp game_move_ok


move_rock_hitbat:
  mov ah, 30h
  lea di, [si+128]
  call move_detonate
  jmp move_rock_end

move_rock_hitspirit:
move_rock_hitman:
  mov ah, 90h
  lea di, [si+128]
  call move_detonate
  jmp move_rock_end



;  Move bat.

_bat_dir	dw 64, 1, -64, -1, 64, 1, -64, -1

move_bat:

  push ax
  push bx
  push di

  mov bl, al
  and bl, 03h
  xor bh, bh
  add bl, bl

    ;  Is there anything to it's left (relative to it's direction)?
  mov di, si
  add di, _bat_dir[bx+6]
  test _level[di], 0F0h
  jnz move_bat_notleft

    ;  If there is nothing left, go that way.
  mov bl, al
  mov ah, al
  add bl, 3
  and ah, 0F0h
  and bl, 3
  mov _level[si], 0
  or ah, bl
  mov _level_flags[di], 1
  mov _level[di], ah

  jmp move_bat_touch

move_bat_notleft:

    ;  There is something on the left to follow round.
    ;  Check if there is anything forward.
  mov di, si
  add di, _bat_dir[bx]
  test _level[di], 0F0h
  jnz move_bat_noforward

  mov _level[si], 0
  mov _level_flags[di], 1
  mov _level[di], al

  jmp move_bat_touch

move_bat_noforward:
    ;  Forward blocked so turn right.
  mov di, si
  add di, _bat_dir[bx+2]
  mov bl, al
  mov ah, al
  inc bl
  and ah, 0F0h
  and bl, 3
  or ah, bl
  mov _level[si], ah

move_bat_touch:

  mov ah, _level[si-64]
  and ah, 0F0h
  cmp ah, 0A0h
  je move_bat_detonate
  cmp ah, 0F0h
  je move_bat_detonate
  mov ah, _level[si+64]
  and ah, 0F0h
  cmp ah, 0A0h
  je move_bat_detonate
  cmp ah, 0F0h
  je move_bat_detonate
  mov ah, _level[si-1]
  and ah, 0F0h
  cmp ah, 0A0h
  je move_bat_detonate
  cmp ah, 0F0h
  je move_bat_detonate
  mov ah, _level[si+1]
  and ah, 0F0h
  cmp ah, 0A0h
  je move_bat_detonate
  cmp ah, 0F0h
  je move_bat_detonate

  pop di
  pop bx
  pop ax
  jmp game_move_ok


move_bat_detonate:

  mov ah, 30h
  mov di, si
  call move_detonate

  pop di
  pop bx
  pop ax
  jmp game_move_ok



;  Move spirit.

_spirit_dir	dw 64, -1, -64, 1, 64, -1, -64, 1

move_spirit:

  push ax
  push bx
  push di

  mov bl, al
  and bl, 03h
  xor bh, bh
  add bl, bl

    ;  Is there anything to it's left (relative to it's direction)?
  mov di, si
  add di, _spirit_dir[bx+6]
  test _level[di], 0F0h
  jnz move_spirit_notleft

    ;  If there is nothing left, go that way.
  mov bl, al
  mov ah, al
  add bl, 3
  and ah, 0F0h
  and bl, 3
  mov _level[si], 0
  or ah, bl
  mov _level_flags[di], 1
  mov _level[di], ah

  jmp move_spirit_touch

move_spirit_notleft:

    ;  There is something on the left to follow round.
    ;  Check if there is anything forward.
  mov di, si
  add di, _spirit_dir[bx]
  test _level[di], 0F0h
  jnz move_spirit_noforward

  mov _level[si], 0
  mov _level_flags[di], 1
  mov _level[di], al

  jmp move_spirit_touch

move_spirit_noforward:
    ;  Forward blocked so turn right.
  mov di, si
  add di, _spirit_dir[bx+2]
  mov bl, al
  mov ah, al
  inc bl
  and ah, 0F0h
  and bl, 3
  or ah, bl
  mov _level[si], ah

move_spirit_touch:

  mov ah, _level[si-64]
  and ah, 0F0h
  cmp ah, 0A0h
  je move_spirit_detonate
  cmp ah, 0F0h
  je move_spirit_detonate
  mov ah, _level[si+64]
  and ah, 0F0h
  cmp ah, 0A0h
  je move_spirit_detonate
  cmp ah, 0F0h
  je move_spirit_detonate
  mov ah, _level[si-1]
  and ah, 0F0h
  cmp ah, 0A0h
  je move_spirit_detonate
  cmp ah, 0F0h
  je move_spirit_detonate
  mov ah, _level[si+1]
  and ah, 0F0h
  cmp ah, 0A0h
  je move_spirit_detonate
  cmp ah, 0F0h
  je move_spirit_detonate

  pop di
  pop bx
  pop ax
  jmp game_move_ok


move_spirit_detonate:

  mov ah, 90h
  mov di, si
  call move_detonate

  pop di
  pop bx
  pop ax
  jmp game_move_ok



;  Move man.

_move_man_left	db 58h, 59h, 5Ah, 5Bh, 5Ch, 5Dh, 5Bh, 5Ah, 59h, -1
_move_man_right	db 60h, 61h, 62h, 63h, 64h, 65h, 64h, 63h, 62h, -1
_move_man_ptr	dw offset _move_man_right
_move_man_dir	dw offset _move_man_right
_move_man_push	db 00h


move_man:
  push ax
  mov _playerok, 1
  mov _game_play_bar, 0

  inc _move_man_push
  and _move_man_push, 0Fh
  mov _level[si], 0F0h

    ;  Up?

  xor al, al

  cmp _KBD_UP, 0
  je move_man_noup

  mov _level[si], 0F1h
  cmp _level[si-64], 30h
  jnb move_man_noup
  mov al, _level[si-64]
  mov cs: _game_man_frame, offset cs: _game_man_anim
  cmp _KBD_FIRE, 0
  je move_man_up_nofire
  mov _level[si-64], 90h
  mov _level_flags[si-64], 1
  jmp move_man_after
move_man_up_nofire:
  dec _player_y
  sub _player_off, 64
  mov _level[si], 0
  mov _level[si-64], 0F1h
  mov _level_flags[si-64], 1
  jmp move_man_after

move_man_noup:

    ;  Down?

  cmp _KBD_DOWN, 0
  je move_man_nodown

  mov _level[si], 0F1h
  cmp _level[si+64], 30h
  jnb move_man_nodown
  mov al, _level[si+64]
  mov cs: _game_man_frame, offset cs: _game_man_anim
  cmp _KBD_FIRE, 0
  je move_man_down_nofire
  mov _level[si+64], 90h
  mov _level_flags[si+64], 1
  jmp move_man_after
move_man_down_nofire:
  inc _player_y
  add _player_off, 64
  mov _level[si], 0
  mov _level[si+64], 0F1h
  mov _level_flags[si+64], 1
  jmp move_man_after

move_man_nodown:

    ;  Left?

  cmp _KBD_LEFT, 0
  je move_man_noleft

  mov _level[si], 0F1h
  cmp _move_man_dir, offset _move_man_left
  je move_man_leftok
  mov _move_man_dir, offset _move_man_left
  mov _move_man_ptr, offset _move_man_left
move_man_leftok:

  mov ah, _level[si-1]
  and ah, 0F0h
  cmp ah, 60h
  jne move_man_noleftpush
  cmp _move_man_push, 0
  jne move_man_noleftpush
  test _level[si-2], 0F0h
  jnz move_man_noleftpush
  mov ah, _level[si-1]
  mov _level[si-2], ah
  mov _level[si-1], 0
move_man_noleftpush:

  cmp _level[si-1], 30h
  jnb move_man_noleft
  mov al, _level[si-1]
  mov cs: _game_man_frame, offset cs: _game_man_anim
  cmp _KBD_FIRE, 0
  je move_man_left_nofire
  mov _level[si-1], 90h
  mov _level_flags[si-1], 1
  jmp move_man_after
move_man_left_nofire:
  dec _player_x
  dec _player_off
  mov _level[si], 0
  mov _level[si-1], 0F1h
  mov _level_flags[si-1], 1
  jmp move_man_after

move_man_noleft:

    ;  Right?

  cmp _KBD_RIGHT, 0
  je move_man_noright

  mov ah, _level[si+1]
  and ah, 0F0h
  cmp ah, 60h
  jne move_man_norightpush
  cmp _move_man_push, 0
  jne move_man_norightpush
  test _level[si+2], 0F0h
  jnz move_man_norightpush
  mov ah, _level[si+1]
  mov _level[si+2], ah
  mov _level[si+1], 0
move_man_norightpush:

  mov _level[si], 0F1h
  cmp _move_man_dir, offset _move_man_right
  je move_man_rightok
  mov _move_man_dir, offset _move_man_right
  mov _move_man_ptr, offset _move_man_right
move_man_rightok:

  cmp _level[si+1], 30h
  jnb move_man_noright
  mov al, _level[si+1]
  mov cs: _game_man_frame, offset cs: _game_man_anim
  cmp _KBD_FIRE, 0
  je move_man_right_nofire
  mov _level[si+1], 90h
  mov _level_flags[si+1], 1
  jmp move_man_after
move_man_right_nofire:
  inc _player_x
  inc _player_off
  mov _level[si], 0
  mov _level[si+1], 0F1h
  mov _level_flags[si+1], 1
  jmp move_man_after

move_man_noright:

move_man_after:

  and al, 0F0h
  cmp al, 20h
  jne move_man_notdia
  xor ah, ah
  mov al, _level_points
  add word ptr _score, ax
  adc word ptr _score[4], 0
  cmp _level_dias, 0
  je move_man_notdia
  dec _level_dias
move_man_notdia:

  pop ax

  jmp game_move_ok



;---- Move_Detonate.

move_detonate:
  push di
  sub di, 65
  call move_detonate_put
  inc di
  call move_detonate_put
  inc di
  call move_detonate_put
  add di, 62
  call move_detonate_put
  inc di
  call move_detonate_put
  inc di
  call move_detonate_put
  add di, 62
  call move_detonate_put
  inc di
  call move_detonate_put
  inc di
  call move_detonate_put
  pop di
  ret

move_detonate_put:
  push ax
  mov al, _level[di]
  and al, 0F0h
  cmp al, 0B0h
  je move_detonate_put_end
  cmp al, 0C0h
  je move_detonate_put_end
  cmp al, 0D0h
  je move_detonate_put_end
  mov _level[di], ah
  mov _level_flags[di], 1
move_detonate_put_end:
  pop ax
  ret




;---- BEDLAM GRAPHICS ROUTINES ------------------------------------------------;


;---- Game_Rotate

_game_man_anim	db 36 dup (50h), 51h, 52h, 53h, 52h, 51h
		db 4 dup (50h, 50h, 54h, 54h), 9 dup (55h)
		db 6 dup (50h), 4 dup (55h)
		db 4 dup (50h, 50h, 54h, 54h), 51h, 52h, 53h, 52h, 51h, 50h
		db -1

_game_man_frame	dw offset _game_man_anim


;  Rotate sprites.

game_rotate:
  push ax
  push bx

    ;  Man.

  mov bx, _game_man_frame
  mov al, cs: [bx]
  inc bx
  cmp al, -1
  jne game_rotate_manok
  mov bx, offset cs: _game_man_anim
  mov al, cs: [bx]
game_rotate_manok:
  mov _game_man_frame, bx
  mov byte ptr _sprite_table[0F0h], al

  mov bx, _move_man_ptr
  mov al, cs: [bx]
  inc bx
  cmp al, -1
  jne move_man_frameok
  mov bx, _move_man_dir
  mov al, cs: [bx]
move_man_frameok:
  mov _move_man_ptr, bx
  mov byte ptr _sprite_table[0F1h], al

    ;  Diamond.

  mov al, byte ptr _sprite_table[20h]
  mov bx, 20h
  inc al
  cmp al, 4Ah
  jna game_rotate_diaok
  mov al, 40h
game_rotate_diaok:
  mov ah, al
  call game_rotate_put

    ;  Others.

  mov ah, 10h
  mov bx, 40h
  call game_rotate_one
  mov ah, 18h
  mov bx, 50h
  call game_rotate_one
  mov ah, 20h
  mov bx, 80h
  call game_rotate_one
  mov ah, 38h
  mov bx, 0D0h
  call game_rotate_one

  pop bx
  pop ax
  ret

game_rotate_one:

  mov al, byte ptr _sprite_table[bx]
  inc al
  and al, 7
  or al, ah
  mov ah, al

game_rotate_put:
  mov word ptr _sprite_table[bx], ax
  mov word ptr _sprite_table[bx+2], ax
  mov word ptr _sprite_table[bx+4], ax
  mov word ptr _sprite_table[bx+6], ax
  mov word ptr _sprite_table[bx+8], ax
  mov word ptr _sprite_table[bx+10], ax
  mov word ptr _sprite_table[bx+12], ax
  mov word ptr _sprite_table[bx+14], ax

  ret



;---- Game_Scroll.

game_scroll:
  push ax

    ;  Sort out tx and ty.

  cmp _corner_tx, 245
  jna game_scroll_txok
  mov _corner_tx, 0
game_scroll_txok:

  cmp _corner_ty, 245
  jna game_scroll_tyok
  mov _corner_ty, 0
game_scroll_tyok:


    ;  Horizontal movement.

  mov al, _corner_x
  cmp al, _corner_tx
  je game_scroll_nohoriz
  jb game_scroll_right

  mov al, _level_minx
  cmp _corner_x, al
  je game_scroll_nohoriz
  dec _corner_x
  dec _corner_off
  call game_back_left
;  call game_back_left
;  call game_back_left
  jmp game_scroll_nohoriz

game_scroll_right:
  mov ah, _level_width
  sub ah, 20
  cmp _corner_x, ah
  jae game_scroll_nohoriz
  inc _corner_x
  inc _corner_off
  call game_back_right
;  call game_back_right
;  call game_back_right

game_scroll_nohoriz:

    ;  Vertical movement.

  mov al, _corner_y
  cmp al, _corner_ty
  je game_scroll_novert
  jl game_scroll_down

  mov al, _level_miny
  cmp _corner_y, al
  je game_scroll_novert
  dec _corner_y
  sub _corner_off, 64
  call game_back_up
;  call game_back_up
;  call game_back_up
  jmp game_scroll_novert

game_scroll_down:
  mov ah, _level_height
  sub ah, 12
  cmp _corner_y, ah
  jge game_scroll_novert
  inc _corner_y
  add _corner_off, 64
  call game_back_down
;  call game_back_down
;  call game_back_down

game_scroll_novert:

    ;  Scroll if necessary.

  mov al, _player_x
  sub al, _corner_x
  cmp al, 4
  jb game_scroll_manleft
  cmp al, 14
  jb game_scroll_afterhoriz

  mov al, _player_x
  sub al, 9
  mov _corner_tx, al
  jmp game_scroll_afterhoriz

game_scroll_manleft:

  mov al, _player_x
  sub al, 8
  mov _corner_tx, al

game_scroll_afterhoriz:

  mov al, _player_y
  sub al, _corner_y
  cmp al, 4
  jl game_scroll_manup
  cmp al, 8
  jl game_scroll_aftervert

  mov al, _player_y
  sub al, 5
  mov _corner_ty, al
  jmp game_scroll_aftervert

game_scroll_manup:

  mov al, _player_y
  sub al, 6
  mov _corner_ty, al

game_scroll_aftervert:

  pop ax
  ret


game_back_up:
  push ds
  push es
  push cx
  push si
  push di

  mov ds, _code_seg
  mov es, _code_seg

  cld
  mov cx, 32
  mov si, offset cs: _game_back_data + 32*31
  mov di, offset cs: _game_back_data + 32*32
game_back_up_loop:
  push cx
  mov cx, 16
  rep movsw
  pop cx
  sub si, 64
  sub di, 64
  loop game_back_up_loop

  mov si, offset cs: _game_back_data + 32*32
  mov di, offset cs: _game_back_data
  mov cx, 16
  rep movsw

  pop di
  pop si
  pop cx
  pop es
  pop ds
  ret


game_back_down:
  push ds
  push es
  push cx
  push si
  push di

  mov ds, _code_seg
  mov es, _code_seg

  cld

  mov si, offset cs: _game_back_data
  mov di, offset cs: _game_back_data + 32*32
  mov cx, 16
  rep movsw

  mov cx, 32
  mov si, offset cs: _game_back_data + 32
  mov di, offset cs: _game_back_data
game_back_down_loop:
  push cx
  mov cx, 16
  rep movsw
  pop cx
  loop game_back_down_loop

  pop di
  pop si
  pop cx
  pop es
  pop ds
  ret


game_back_right:
  push ds
  push es
  push cx
  push si
  push di

  cld
  mov ds, _code_seg
  mov es, _code_seg

  mov si, offset cs: _game_back_data
  mov di, offset cs: _game_back_data

  mov cx, 32
game_back_right_loop:
  push cx

  lodsb
  mov cx, 31
  rep movsb
  stosb

  pop cx
  loop game_back_right_loop

  pop di
  pop si
  pop cx
  pop es
  pop ds
  ret


game_back_left:
  push ds
  push es
  push cx
  push si
  push di

  cld
  mov ds, _code_seg
  mov es, _code_seg

  mov si, offset cs: _game_back_data+31

  mov cx, 32
game_back_left_loop:
  push cx

  mov ch, [si]
  mov cl, 31
game_back_left_xloop:

  mov al, [si-1]
  mov [si], al

  dec si
  dec cl
  jnz game_back_left_xloop

  mov [si], ch
  add si, 63
  pop cx
  loop game_back_left_loop

  pop di
  pop si
  pop cx
  pop es
  pop ds
  ret



;---- Game_SozzleFrame.

game_sozzleframe:

  push es
  push ds
  push ax
  push bx
  push dx
  push si
  push di

  call game_scroll

    ;  Rotate animated sprites.
  call game_rotate

  mov ds, _code_seg
  mov es, _scr_seg

  call game_back

  xor bx, bx
  mov dh, 12
  mov si, _corner_off
  add si, offset _level
  mov di, 0
game_sozzleframe_ysozzle:
  mov dl, 20
  push di
game_sozzleframe_xsozzle:

  mov al, _game_sozzle_buf[bx]
  cmp al, _game_sozzle_frame
  jae game_sozzleframe_block

  mov al, [si]
  call blit

  jmp game_sozzleframe_next

game_sozzleframe_block:

  mov al, _game_sozzle_block
  call blit

game_sozzleframe_next:
  inc bx
  inc si
  add di, 16
  dec dl
  jnz game_sozzleframe_xsozzle

  pop di
  add di, 320*16
  add si, 64-20
  dec dh
  jnz game_sozzleframe_ysozzle

  inc _game_sozzle_block
  and _game_sozzle_block, 7
  or _game_sozzle_block, 0D0h

  pop di
  pop si
  pop dx
  pop bx
  pop ax
  pop ds
  pop es

  ret



;---- Game_Frame.

game_frame:

  push es
  push ds
  push ax
  push bx
  push dx
  push si
  push di

  call game_scroll

    ;  Rotate animated sprites.
  call game_rotate

  mov ds, _code_seg
  mov es, _scr_seg

  call game_back

  xor bx, bx
  mov dh, 12
  mov si, _corner_off
  add si, offset _level
  mov di, 0
game_frame_y:
  mov dl, 20
  push si
  push di
game_frame_x:

  mov al, [si]
  call blit

  inc bx
  inc si
  add di, 16
  dec dl
  jnz game_frame_x

  pop di
  pop si
  add di, 320*16
  add si, 64
  dec dh
  jnz game_frame_y

  pop di
  pop si
  pop dx
  pop bx
  pop ax
  pop ds
  pop es

  ret



;---- Game_Back.

_game_back_data	dd 00h, 01D1D1D1Ch, 01E1D1D1Dh, 00h
		dd 00h, 00h, 00h, 00h
		dd 00h, 01D1D1D1Ch, 01E1D1D1Dh, 00h
		dd 00h, 00h, 00h, 00h
		dd 00h, 01D1D1D1Ch, 01E1D1D1Dh, 00h
		dd 00h, 00h, 00h, 00h
		dd 01C1C1C1Ch, 01D1D1D1Ch, 01D1D1D1Dh, 01C1C1C1Ch
		dd 01C1C1C1Ch, 01C1C1C1Ch, 01C1C1C1Ch, 01C1C1C1Ch
		dd 01D1D1D1Dh, 01D1D1D1Dh, 01D1D1D1Dh, 01D1D1D1Dh
		dd 01D1D1D1Dh, 01D1D1D1Dh, 01D1D1D1Dh, 01D1D1D1Dh
		dd 01D1D1D1Dh, 01F1D1D1Dh, 01D1D1D1Eh, 01D1D1D1Dh
		dd 01D1D1D1Dh, 01D1D1D1Dh, 01D1D1D1Dh, 01D1D1D1Dh
		dd 01D1D1D1Dh, 01F1D1Dh, 01D1D1C00h, 01D1D1D1Dh
		dd 01D1D1D1Dh, 01D1D1D1Dh, 01D1D1D1Dh, 01D1D1D1Dh
		dd 01D1D1D1Dh, 01E1D1Dh, 01D1D1B00h, 01D1D1D1Dh
		dd 01D1D1D1Dh, 01D1D1D1Dh, 01D1D1D1Dh, 01D1D1D1Dh
		dd 01D1D1D1Dh, 01C1D1D1Dh, 01D1D1D1Bh, 01D1D1D1Dh
		dd 01D1D1D1Dh, 01D1D1D1Dh, 01D1D1D1Dh, 01D1D1D1Dh
		dd 01D1D1D1Dh, 01D1D1D1Dh, 01D1D1D1Dh, 01D1D1D1Dh
		dd 01D1D1D1Dh, 01D1D1D1Dh, 01D1D1D1Dh, 01D1D1D1Dh
		dd 01E1E1E1Eh, 01D1D1D1Dh, 01E1D1D1Dh, 01E1E1E1Eh
		dd 01E1E1E1Eh, 01E1E1E1Eh, 01E1E1E1Eh, 01E1E1E1Eh
		dd 00h, 01D1D1D1Ch, 01E1D1D1Dh, 00h
		dd 00h, 00h, 00h, 00h
		dd 00h, 01D1D1D1Ch, 01E1D1D1Dh, 00h
		dd 00h, 00h, 00h, 00h
		dd 00h, 01D1D1D1Ch, 01E1D1D1Dh, 00h
		dd 00h, 00h, 00h, 00h
		dd 00h, 01D1D1D1Ch, 01E1D1D1Dh, 00h
		dd 00h, 00h, 00h, 00h
		dd 00h, 01D1D1D1Ch, 01E1D1D1Dh, 00h
		dd 00h, 00h, 00h, 00h
		dd 00h, 01D1D1D1Ch, 01E1D1D1Dh, 00h
		dd 00h, 00h, 00h, 00h
		dd 00h, 01D1D1D1Ch, 01E1D1D1Dh, 00h
		dd 00h, 00h, 00h, 00h
		dd 00h, 01D1D1D1Ch, 01E1D1D1Dh, 00h
		dd 00h, 00h, 00h, 00h
		dd 00h, 01D1D1D1Ch, 01E1D1D1Dh, 00h
		dd 00h, 00h, 00h, 00h
		dd 00h, 01D1D1D1Ch, 01E1D1D1Dh, 00h
		dd 00h, 00h, 00h, 00h
		dd 00h, 01D1D1D1Ch, 01E1D1D1Dh, 00h
		dd 00h, 00h, 00h, 00h
		dd 00h, 01D1D1D1Ch, 01E1D1D1Dh, 00h
		dd 00h, 00h, 00h, 00h
		dd 00h, 01D1D1D1Ch, 01E1D1D1Dh, 00h
		dd 00h, 00h, 00h, 00h
		dd 00h, 01D1D1D1Ch, 01E1D1D1Dh, 00h
		dd 00h, 00h, 00h, 00h
		dd 00h, 01D1D1D1Ch, 01E1D1D1Dh, 00h
		dd 00h, 00h, 00h, 00h
		dd 00h, 01D1D1D1Ch, 01E1D1D1Dh, 00h
		dd 00h, 00h, 00h, 00h
		dd 00h, 01D1D1D1Ch, 01E1D1D1Dh, 00h
		dd 00h, 00h, 00h, 00h
		dd 00h, 01D1D1D1Ch, 01E1D1D1Dh, 00h
		dd 00h, 00h, 00h, 00h
		dd 00h, 01D1D1D1Ch, 01E1D1D1Dh, 00h
		dd 00h, 00h, 00h, 00h
		dd 00h, 01D1D1D1Ch, 01E1D1D1Dh, 00h
		dd 00h, 00h, 00h, 00h
		dd 00h, 01D1D1D1Ch, 01E1D1D1Dh, 00h
		dd 00h, 00h, 00h, 00h
		dd 8 dup (00000000h)


game_back:
  push ds
  push ax
  push cx
  push dx
  push esi
  push edi

  cld

  mov ds, _code_seg
  xor esi, esi
  xor edi, edi

  mov dh, 6
game_back_yloop:

  push di
  mov dl, 10
game_back_xloop:

  mov si, offset cs: _game_back_data
  push di
  mov al, 32
game_back_yblit:

  mov cx, 8
  rep movsd

  add di, 320-32
  dec al
  jnz game_back_yblit

  pop di
  add di, 32
  dec dl
  jnz game_back_xloop

  pop di
  add di, 320*32
  dec dh
  jnz game_back_yloop

  pop edi
  pop esi
  pop dx
  pop cx
  pop ax
  pop ds
  ret



;---- Game_Status.

_game_digits	dd 0FFFFFF00h, 0FFFFh, 0FFh, 0FF0000h
		dd 0FFh, 0FFFF00h, 0FFh, 0FF00FFh
		dd 0FF0000FFh, 0FF0000h, 0FF00FFh, 0FF0000h
		dd 0FFFFh, 0FF0000h, 0FFh, 0FF0000h
		dd 0FFFFFF00h, 0FFFFh, 00h, 00h
		dd 0FF000000h, 00h, 0FFFF0000h, 00h
		dd 0FF00FF00h, 00h, 0FF0000FFh, 00h
		dd 0FF000000h, 00h, 0FF000000h, 00h
		dd 0FF000000h, 00h, 0FF000000h, 00h
		dd 0FFFFFFFFh, 0FFFFFFh, 00h, 00h
		dd 0FFFFFF00h, 0FFFFh, 0FFh, 0FF0000h
		dd 00h, 0FF0000h, 00h, 0FF00h
		dd 00h, 0FFh, 0FF000000h, 00h
		dd 0FF0000h, 00h, 0FF00h, 00h
		dd 0FFFFFFFFh, 0FFFFFFh, 00h, 00h
		dd 0FFFFFFFFh, 0FFFFFFh, 00h, 0FF00h
		dd 00h, 0FFh, 0FF000000h, 00h
		dd 00h, 0FFh, 00h, 0FF00h
		dd 00h, 0FF0000h, 0FFh, 0FF0000h
		dd 0FFFFFF00h, 0FFFFh, 00h, 00h
		dd 00h, 0FF00h, 00h, 0FFFFh
		dd 0FF000000h, 0FF00h, 0FF0000h, 0FF00h
		dd 0FF00h, 0FF00h, 0FFFFFFFFh, 0FFFFFFh
		dd 00h, 0FF00h, 00h, 0FF00h
		dd 00h, 0FF00h, 00h, 00h
		dd 0FFFFFFFFh, 0FFFFFFh, 0FFh, 00h
		dd 0FFh, 00h, 0FFFFFFFFh, 0FFFFh
		dd 00h, 0FF0000h, 00h, 0FF0000h
		dd 00h, 0FF0000h, 0FFh, 0FF0000h
		dd 0FFFFFF00h, 0FFFFh, 00h, 00h
		dd 0FFFFFF00h, 0FFFFh, 0FFh, 0FF0000h
		dd 0FFh, 00h, 0FFFFFFFFh, 0FFFFh
		dd 0FFh, 0FF0000h, 0FFh, 0FF0000h
		dd 0FFh, 0FF0000h, 0FFh, 0FF0000h
		dd 0FFFFFF00h, 0FFFFh, 00h, 00h
		dd 0FFFFFFFFh, 0FFFFFFh, 00h, 0FF0000h
		dd 00h, 0FF0000h, 00h, 0FF00h
		dd 00h, 0FFh, 0FF000000h, 00h
		dd 0FF000000h, 00h, 0FF000000h, 00h
		dd 0FF000000h, 00h, 00h, 00h
		dd 0FFFFFF00h, 0FFFFh, 0FFh, 0FF0000h
		dd 0FFh, 0FF0000h, 0FFh, 0FF0000h
		dd 0FFFFFF00h, 0FFFFh, 0FFh, 0FF0000h
		dd 0FFh, 0FF0000h, 0FFh, 0FF0000h
		dd 0FFFFFF00h, 0FFFFh, 00h, 00h
		dd 0FFFFFF00h, 0FFFFh, 0FFh, 0FF0000h
		dd 0FFh, 0FF0000h, 0FFh, 0FF0000h
		dd 0FFFFFF00h, 0FFFFFFh, 00h, 0FF0000h
		dd 00h, 0FF0000h, 0FFh, 0FF0000h
		dd 0FFFFFF00h, 0FFFFh, 00h, 00h
		dd 00h, 049h, 048000000h, 049B9h
		dd 034470000h, 04A0D23h, 048484700h, 04B0D2334h
		dd 068687948h, 023344857h, 087874900h, 04B576879h
		dd 0944A0000h, 04B7987h, 04B000000h, 04BA8h
		dd 00h, 04Ah, 00h, 00h
		dd 0FFFF0000h, 0FFFFFFh, 0FF00h, 0FF000000h
		dd 0FF00h, 00h, 0FF00h, 00h
		dd 0FF00h, 0FFFFFFFFh, 0FF00h, 0FF000000h
		dd 0FF00h, 0FF000000h, 0FF00h, 0FF000000h
		dd 0FFFF0000h, 0FFFFFFh, 00h, 00h
		dd 0FFFF0000h, 0FFFFFFh, 0FF00h, 0FF000000h
		dd 0FF00h, 0FF000000h, 0FF00h, 0FF000000h
		dd 0FFFFFF00h, 0FFFFFFFFh, 0FF00h, 0FF000000h
		dd 0FF00h, 0FF000000h, 0FF00h, 0FF000000h
		dd 0FF00h, 0FF000000h, 00h, 00h
		dd 0FF00h, 0FF000000h, 0FFFF00h, 0FFFF0000h
		dd 0FF00FF00h, 0FF00FF00h, 0FF00h, 0FF0000FFh
		dd 0FF00h, 0FF000000h, 0FF00h, 0FF000000h
		dd 0FF00h, 0FF000000h, 0FF00h, 0FF000000h
		dd 0FF00h, 0FF000000h, 00h, 00h
		dd 0FFFFFF00h, 0FFFFFFFFh, 0FF00h, 00h
		dd 0FF00h, 00h, 0FF00h, 00h
		dd 0FFFFFF00h, 0FFFFh, 0FF00h, 00h
		dd 0FF00h, 00h, 0FF00h, 00h
		dd 0FFFFFF00h, 0FFFFFFFFh, 00h, 00h
		dd 00h, 00h, 00h, 00h
		dd 00h, 00h, 00h, 00h
		dd 00h, 00h, 00h, 00h
		dd 00h, 00h, 00h, 00h
		dd 00h, 00h, 00h, 00h
		dd 0FFFF0000h, 0FFFFFFh, 0FF00h, 0FF000000h
		dd 0FF00h, 0FF000000h, 0FF00h, 0FF000000h
		dd 0FF00h, 0FF000000h, 0FF00h, 0FF000000h
		dd 0FF00h, 0FF000000h, 0FF00h, 0FF000000h
		dd 0FFFF0000h, 0FFFFFFh, 00h, 00h
		dd 0FF00h, 0FF000000h, 0FF00h, 0FF000000h
		dd 0FF00h, 0FF000000h, 0FF00h, 0FF000000h
		dd 0FF00h, 0FF000000h, 0FF00h, 0FF000000h
		dd 0FF0000h, 0FF0000h, 0FF000000h, 0FF00h
		dd 00h, 0FFh, 00h, 00h
		dd 0FFFFFF00h, 0FFFFFFh, 0FF00h, 0FF000000h
		dd 0FF00h, 0FF000000h, 0FF00h, 0FF000000h
		dd 0FFFFFF00h, 0FFFFFFh, 0FF00h, 0FFh
		dd 0FF00h, 0FF00h, 0FF00h, 0FF0000h
		dd 0FF00h, 0FF000000h, 00h, 00h
		dd 00h, 00h, 00h, 00h
		dd 00h, 00h, 00h, 00h
		dd 0FFFF0000h, 0FFFFFFh, 00h, 00h
		dd 00h, 00h, 00h, 00h
		dd 00h, 00h, 00h, 00h
		dd 0FFFFFF00h, 0FFFFFFh, 0FF00h, 0FF000000h
		dd 0FF00h, 0FF000000h, 0FF00h, 0FF000000h
		dd 0FFFFFF00h, 0FFFFFFh, 0FF00h, 00h
		dd 0FF00h, 00h, 0FF00h, 00h
		dd 0FF00h, 00h, 00h, 00h
		dd 0FFFF0000h, 0FFFFFFh, 0FF00h, 0FF000000h
		dd 0FF00h, 00h, 0FF00h, 00h
		dd 0FFFF0000h, 0FFFFFFh, 00h, 0FF000000h
		dd 00h, 0FF000000h, 0FF00h, 0FF000000h
		dd 0FFFF0000h, 0FFFFFFh, 00h, 00h
		dd 0FFFF0000h, 0FFFFFFh, 0FF00h, 0FF000000h
		dd 0FF00h, 00h, 0FF00h, 00h
		dd 0FF00h, 00h, 0FF00h, 00h
		dd 0FF00h, 00h, 0FF00h, 0FF000000h
		dd 0FFFF0000h, 0FFFFFFh, 00h, 00h
		dd 0FFFFFF00h, 0FFFFFFFFh, 00h, 0FFh
		dd 00h, 0FFh, 00h, 0FFh
		dd 00h, 0FFh, 00h, 0FFh
		dd 00h, 0FFh, 00h, 0FFh
		dd 00h, 0FFh, 00h, 00h
		dd 0FFFF0000h, 0FFFFFFh, 00h, 0FFh
		dd 00h, 0FFh, 00h, 0FFh
		dd 00h, 0FFh, 00h, 0FFh
		dd 00h, 0FFh, 00h, 0FFh
		dd 0FFFF0000h, 0FFFFFFh, 00h, 00h
		dd 0FF00h, 0FF000000h, 0FF00h, 0FF000000h
		dd 0FF00h, 0FF000000h, 0FF00h, 0FF000000h
		dd 0FF00h, 0FF000000h, 0FF00h, 0FF000000h
		dd 0FF00h, 0FF000000h, 0FF00h, 0FF000000h
		dd 0FFFF0000h, 0FFFFFFh, 00h, 00h


game_status:
  push es
  push eax
  push cx
  push edx
  push ebx
  push si
  push di

  mov es, _scr_seg
  mov di, 64000-8*320
  mov cx, 320*8/2
  xor ax, ax
  rep stosw
  mov di, (160-18*8/2)+190*320

    ;  Score per diamond.

  mov al, _level_points
  call game_3digit

    ;  Diamond icon.

  mov al, 10
  call game_digit
  mov byte ptr es: [di+323], 0
  mov byte ptr es: [di+325], 0
  mov byte ptr es: [di+4], 0
  mov al, byte ptr es: [di+7+4*320]
  mov byte ptr es: [di+8+5*320], al
  add di, 10

    ;  Number of diamonds left.

  mov al, _level_dias
  call game_3digit

    ;  Score.

  mov eax, _score
  mov ebx, 10
  mov cx, 6
game_status_scorecalc:
  xor edx, edx
  div ebx
  push dx
  loop game_status_scorecalc

  mov cx, 6
game_status_scoreblit:
  pop ax
  add di, 8
  call game_digit
  loop game_status_scoreblit
  add di, 8

    ;  Time.

  add di, 8
  mov al, _level_time
  call game_3digit

  pop di
  pop si
  pop ebx
  pop edx
  pop cx
  pop eax
  pop es
  ret


game_3digit:
  mov dl, 10
  xor ah, ah
  div dl
  push ax
  xor ah, ah
  div dl
  push ax
  xor ah, ah
  div dl

  mov al, ah
  call game_digit
  add di, 8
  pop ax
  mov al, ah
  call game_digit
  add di, 8
  pop ax
  mov al, ah
  call game_digit
  add di, 8
  ret

		;  G  A  M  E  .  O  V  E  R  .  -  .  P  R  E  S  S  .  S  P  A  C  E
_game_gameover	db 11,12,13,14,15,16,17,14,18,15,19,15,20,18,14,21,21,15,21,20,12,22,14,-1

game_gameover:
  push es
  push ax
  push cx
  push bx
  push di

  mov es, _scr_seg
  mov di, 64000-8*320
  mov cx, 320*8/2
  xor ax, ax
  rep stosw

  xor bx, bx
  mov cx, 23
  mov di, (160-23*8/2)+190*320
game_gameover_loop:
  mov al, _game_gameover[bx]
  call game_digit
  inc bx
  add di, 8
  loop game_gameover_loop

  pop di
  pop bx
  pop cx
  pop ax
  pop es
  ret


		;  T  I  M  E  .  O  U  T  .  -  .  P  R  E  S  S  .  S  P  A  C  E
_game_timeout	db 23,24,13,14,15,16,25,23,15,19,15,20,18,14,21,21,15,21,20,12,22,14,-1

game_timeout:
  push es
  push ax
  push cx
  push bx
  push di

  mov es, _scr_seg
  mov di, 64000-8*320
  mov cx, 320*8/2
  xor ax, ax
  rep stosw

  xor bx, bx
  mov cx, 22
  mov di, (160-22*8/2)+190*320
game_timeout_loop:
  mov al, _game_timeout[bx]
  call game_digit
  inc bx
  add di, 8
  loop game_timeout_loop

  pop di
  pop bx
  pop cx
  pop ax
  pop es
  ret


game_digit:
  push eax
  push cx
  push dx
  push ebx
  push si
  push di

  mov dx, 80
  xor ah, ah
  mul dx
  mov si, ax
  add si, offset _game_digits

    ;  Shadow.
  mov eax, cs: [si]
  mov ebx, cs: [si+4]
  not eax
  not ebx
  and es: [di], eax
  and es: [di+4], ebx
  mov eax, cs: [si+8]
  mov ebx, cs: [si+12]
  not eax
  not ebx
  and es: [di+320], eax
  and es: [di+324], ebx

    ;  Digit.
  mov cx, 10
game_digit_loop:
  mov eax, cs: [si]
  mov ebx, cs: [si+4]
  or es: [di+320], eax
  or es: [di+324], ebx
  add si, 8
  add di, 320
  loop game_digit_loop

  pop di
  pop si
  pop ebx
  pop dx
  pop cx
  pop eax
  ret



;---- Game_Map.

game_map:
  push es
  push ax
  push cx
  push bx
  push di

  mov es, _scr_seg
  mov bx, offset _level
  mov di, (320-64)+(200-64)*320
  mov ch, 64
game_map_yloop:
  mov cl, 64
game_map_xloop:
  mov al, cs: [bx]
  cmp al, 0
  je game_map_ok
  mov al, -1
game_map_ok:
  stosb
  inc bx
  dec cl
  jnz game_map_xloop
  add di, 320-64
  dec ch
  jnz game_map_yloop

  pop di
  pop bx
  pop cx
  pop ax
  pop es
  ret



;---- Update.

;  Copies SCR_SEG onto screen.

update:
  push ax
  push dx
  mov dx, 3DAh
update_vrt:
  in al, dx
  test al, 8
  jz update_vrt
  pop dx
  pop ax

  push ds
  push es
  push ecx
  push esi
  push edi
  mov ds, _scr_seg
  mov es, _graph_seg
  xor esi, esi
  xor edi, edi
  mov ecx, 16000
  cld
  rep movsd
  pop edi
  pop esi
  pop ecx
  pop es
  pop ds
  ret



;---- Blit.

;  AL    - Character.
;  ES:DI - Destination.

blit:
  push ds
  push es
  push eax
  push ebx
  push cx
  push si
  push di

    ;  Convert character to sprite number then to offset.
  xor ah, ah
  mov si, ax
  mov ah, byte ptr _sprite_table[si]
  xor al, al
  mov si, ax

    ;  Blit sprite.

  mov ds, _sprite_seg
  mov es, _scr_seg
  mov ah, al
  mov cx, 16
blit_loop:
    ;  AND mask.
  mov eax, [si+32000]
  mov ebx, [si+32004]
  and es: [di], eax
  and es: [di+4], ebx
  mov eax, [si+32008]
  mov ebx, [si+32012]
  and es: [di+8], eax
  and es: [di+12], ebx
    ;  XOR mask.
  mov eax, [si]
  mov ebx, [si+4]
  xor es: [di], eax
  xor es: [di+4], ebx
  mov eax, [si+8]
  mov ebx, [si+12]
  xor es: [di+8], eax
  xor es: [di+12], ebx

  add si, 16
  add di, 320
  loop blit_loop

  pop di
  pop si
  pop cx
  pop ebx
  pop eax
  pop es
  pop ds
  ret




;---- EDITOR ------------------------------------------------------------------;

;---- Editor.

editor:
  call editor_logon
  call editor_main
  call editor_logoff
  ret



;---- Editor_Logon.

editor_logon:
  ret



;---- Editor_Main.

editor_main:
  ret



;---- Editor_Logoff.

editor_logoff:
  ret



;---- LIBRARY ROUTINES v0.2 ---------------------------------------------------;


;---- GetKey

;  Returns key pressed in AL, or zero in AL and scan code in AH or zero in AX if
; no key in buffer.

getkey:
  mov ah, 0Bh
  int 21h
  cmp al, 0FFh
  je getkey_get
  xor ax, ax
  ret
getkey_get:
  mov ah, 7
  int 21h
  cmp al, 0
  je getkey_ext
  xor ah, ah
  ret
getkey_ext:
  mov ah, 7
  int 21h
  mov ah, al
  xor al, al
  ret



;---- PrintC

;  AH    = attribute
;  CS:IP = string
;  ES:DI = destination

_printc_si	dw 0000h

printc:
  mov _printc_si, si
  pop si
  push ax

printc_loop:
  mov al, cs: [si]
  inc si
  or al, al
  je printc_end

  cmp al, 255
  jne printc_notattr

  mov ah, cs: [si]
  inc si
  jmp printc_loop
printc_notattr:

  stosw
  jmp printc_loop
printc_end:

  pop ax
  push si
  mov si, _printc_si
  ret



;---- Print

;  CS:IP = text.

_print_si		dw 0000h

print:
  mov _print_si, si
  pop si
  push ax

print_loop:
  mov al, cs: [si]
  inc si
  or al, al
  je print_end
  int 29h
  jmp print_loop

print_end:
  pop ax
  push si
  mov si, _print_si
  ret



;---- PrintNumC

;  AH    = attribute
;  CH    = base
;  CL    = digits
;  EDX   = Number
;  ES:DI = destination

_printnumc_table	db '0123456789ABCDEF'
_printnumc_attr		db 00h
_printnumc_len		db 00h
_printnumc_base		db 00h

printnumc:
    ;  Valiate input.
  cmp ch, 0
  je printnumc_end
  cmp ch, 16
  ja printnumc_end
  cmp cl, 0
  je printnumc_end
  cmp cl, 8
  ja printnumc_end

  push eax
  push ecx
  push edx
  push ebx

  mov _printnumc_attr, ah
  mov _printnumc_len, cl
  mov _printnumc_base, ch

  xor ch, ch
  mov eax, edx

printnumc_calc:
  xor ebx, ebx
  mov bl, _printnumc_base
  xor edx, edx
  div ebx

  xor bh, bh
  mov bl, dl
  mov dh, _printnumc_attr
  mov dl, _printnumc_table[bx]
  push dx
  loop printnumc_calc

  mov cl, _printnumc_len
printnumc_print:
  pop ax
  stosw
  loop printnumc_print

  pop ebx
  pop edx
  pop ecx
  pop eax

printnumc_end:
  ret



;---- PrintNum

;  CH    = base
;  CL    = digits
;  EDX   = Number

_printnum_table	db '0123456789ABCDEF'
_printnum_len	db 00h
_printnum_base	db 00h

printnum:
    ;  Valiate input.
  cmp ch, 0
  je printnum_end
  cmp ch, 16
  ja printnum_end
  cmp cl, 0
  je printnum_end
  cmp cl, 8
  ja printnum_end

  push eax
  push ecx
  push edx
  push ebx

  mov _printnum_len, cl
  mov _printnum_base, ch

  xor ch, ch
  mov eax, edx

printnum_calc:
  xor ebx, ebx
  mov bl, _printnum_base
  xor edx, edx
  div ebx

  xor bh, bh
  mov bl, dl
  xor dh, dh
  mov dl, _printnum_table[bx]
  push dx
  loop printnum_calc

  mov cl, _printnum_len
printnum_print:
  pop ax
  int 29h
  loop printnum_print

  pop ebx
  pop edx
  pop ecx
  pop eax

printnum_end:
  ret


;---- END OF CODE -------------------------------------------------------------;

END