Subversion Repositories aysalia

Rev

Rev 21 | Rev 23 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1.  
  2. ; Aysalia DOS Launcher
  3. ; Launches aydos1.gam and aydos2.gam
  4. ; Revision 2018-12-07
  5. ; (C) 2018 Daniel Marschall, ViaThinkSoft
  6.  
  7. .model small
  8. .stack 10h
  9.  
  10. ; -------------------------------------------------------
  11.  
  12. .data
  13.  
  14.     exename1  db "AYDOS1.GAM", 0
  15.     exename2  db "AYDOS2.GAM", 0
  16.     cmdargs   db 0, '', 0Dh
  17.  
  18.     dummy_fcb db 36 dup(0)
  19.  
  20.     paramblk  dw 0          ; use environment of parent
  21.               dw cmdargs    ; command line arguments
  22.               dw 0          ; cmdargs_seg
  23.               dw dummy_fcb  ; fcb1
  24.               dw 0          ; fcb1_seg
  25.               dw dummy_fcb  ; fcb2
  26.               dw 0          ; fcb2_seg
  27.  
  28.     menu1     db 13, 10, \
  29.                  13, 10, \
  30.                  13, 10, \
  31.                  13, 10, \
  32.                  '                            Aysalia DOS', 13, 10, \
  33.                  13, 10, \
  34.                  13, 10, \
  35.                  '              Welches Spiel soll gestartet werden?', 13, 10, \
  36.                  13, 10, \
  37.                  '              Dr', 81h, 'cke eine der folgenden Tasten:', 13, 10, \
  38.                  13, 10, \
  39.                  '              1  Aysalia DOS I', 13, 10, \
  40.                  '              2  Aysalia DOS II', 13, 10, \
  41.                  13, 10, \
  42.                  '              9  Beenden', 13, 10, \
  43.                  13, 10, \
  44.                  13, 10, \
  45.                  13, 10, 0
  46.    
  47.     error1    db 13, 10, \
  48.                  'Fehler: Spiel kann nicht gestartet werden. Fehlt eine Datei?', 13, 10, \
  49.                  13, 10, 0
  50.  
  51.     gameover1 db 13, 10, \
  52.                  'Spiel zu Ende!', 13, 10, \
  53.                  13, 10, 0
  54.  
  55. ; -------------------------------------------------------
  56.  
  57. .code
  58.  
  59. clear_vga PROC
  60.     mov     ax, 0A000h
  61.     mov     es, ax
  62.     xor     di, di
  63.     mov     ax, 0
  64.     mov     cx, 64000
  65.     rep     stosb
  66.     ret
  67. clear_vga ENDP
  68.  
  69. set_screen12 PROC
  70.     mov     ah, 0         ; set screen mode
  71.     mov     al, 12h       ; graphic mode, 640x480 pixel, 16 colors (VGA)
  72.     int     10h
  73.     ret
  74. set_screen12 ENDP
  75.  
  76. setup_paramblk PROC
  77.     mov     ax, cs
  78.     mov     [paramblk +  4], ax   ; cmdargs_seg
  79.     mov     [paramblk +  8], ax   ; fcb1_seg
  80.     mov     [paramblk + 12], ax   ; fcb2_seg
  81.     ret
  82. setup_paramblk ENDP
  83.  
  84. set_numlock_on PROC
  85.     push    ds
  86.     mov     ax, 40h
  87.     mov     ds, ax        ; Go to BIOS Data Area ( http://stanislavs.org/helppc/bios_data_area.html )
  88.     mov     bx, 17h       ; Load Keyboard flag byte 0
  89.     mov     al, [bx]      ; Read
  90.     or      al, 20h       ; Set bit 5 (numlock) to 1
  91.     mov     [bx], al      ; Write
  92.     pop     ds
  93.     ret
  94. set_numlock_on ENDP
  95.  
  96. flush_keyb_buf PROC
  97.     mov     ah, 0Ch       ; Flush input buffer and input
  98.     mov     al, 0
  99.     int     21h
  100.     ret
  101. flush_keyb_buf ENDP
  102.  
  103. exit_to_dos PROC
  104.     mov     ah, 4Ch
  105.     mov     al, 00h
  106.     int     21h
  107.     ret
  108. exit_to_dos ENDP
  109.  
  110. sleep_5 PROC
  111.     mov     ah, 00h
  112.     int     1Ah
  113.     cmp     dx, 7FFFh
  114.     jg      sleep_5_upperhalf
  115. sleep_5_lowerhalf:
  116.     mov     bx, dx
  117.     add     bx, 91        ; 18.2 = 1 sec (therefore 91 = 5 sec)
  118. sleep_5_lowerhalf_again:
  119.     int     1Ah
  120.     cmp     dx, bx
  121.     jl      sleep_5_lowerhalf_again
  122.     ret
  123. sleep_5_upperhalf:
  124.     mov     bx, dx
  125.     sub     bx, 7FFFh
  126.     add     bx, 91        ; 18.2 = 1 sec (therefore 91 = 5 sec)
  127. sleep_5_upperhalf_again:
  128.     int     1Ah
  129.     sub     dx, 7FFFh
  130.     cmp     dx, bx
  131.     jl      sleep_5_upperhalf_again
  132.     ret
  133. sleep_5 ENDP
  134.  
  135. print_color_string PROC
  136.     ; This function requires:
  137.     ; dx = Pointer to zero terminated string
  138.     ; cl = Color
  139.     mov     ah, 0Eh
  140. print_color_string_again:
  141.     mov     al, 0
  142.     mov     bx, dx
  143.     cmp     [bx], al
  144.     je      print_color_string_end
  145.     mov     al, [bx]
  146.     mov     bl, cl
  147.     int     10h
  148.     add     dx, 1
  149.     jmp     print_color_string_again
  150. print_color_string_end:
  151.     ret
  152. print_color_string ENDP
  153.  
  154. set_bg_color PROC
  155.     ; This function requires:
  156.     ; bl = Color
  157.     mov     ah, 0Bh
  158.     mov     bh, 00h
  159.     int     10h
  160.     ret
  161. set_bg_color ENDP
  162.  
  163. print_menu_screen PROC
  164.     ; Move cursor to 0, 0
  165.     mov     ah, 02h       ; set cursor position
  166.     mov     dh, 0         ; line
  167.     mov     dl, 0         ; column
  168.     mov     bh, 0         ; page
  169.     int     10h
  170.  
  171.     ; Set background color
  172.     mov     bl, 8         ; dark green background
  173.     call    set_bg_color
  174.    
  175.     ; Set text color
  176.     mov     cl, 0Fh       ; white font
  177.     lea     dx, menu1
  178.     call    print_color_string
  179.    
  180.     ret
  181. print_menu_screen ENDP
  182.  
  183. print_error_screen PROC
  184.     ; Move cursor to 0, 0
  185.     mov     ah, 02h       ; set cursor position
  186.     mov     dh, 0         ; line
  187.     mov     dl, 0         ; column
  188.     mov     bh, 0         ; page
  189.     int     10h
  190.  
  191.     ; Set background color
  192.     mov     bl, 4         ; dark red background
  193.     call    set_bg_color
  194.    
  195.     ; Set text color
  196.     mov     cl, 0Fh       ; white font
  197.     lea     dx, error1
  198.     call    print_color_string
  199.    
  200.     ret
  201. print_error_screen ENDP
  202.  
  203. print_gameover_screen PROC
  204.     ; Keep cursor position
  205.  
  206.     ; Set background color
  207.     mov     bl, 4    ; dark red background
  208.     call    set_bg_color
  209.    
  210.     ; Set text color
  211.     mov     cl, 0Fh  ; white font
  212.     lea     dx, gameover1
  213.     call    print_color_string
  214.    
  215.     ret
  216. print_gameover_screen ENDP
  217.  
  218. ; -------------------------------------------------------
  219.  
  220. start:
  221.     ; Setup data segment
  222.     mov     ax, @data     ; moving base address of data to ax
  223.     mov     ds, ax        ; moving contents of ax into ds
  224.                           ; data section now gets initialized                                        
  225.  
  226.     ; Preserve the original screen mode
  227.     mov     ah, 0Fh       ; Query screen mode
  228.     int     10h
  229.     push    ax            ; actually, we are only interested in register al (screen mode), not in ah (column count)
  230.    
  231.     ; Change numlock to ON
  232.     ; DOSBox has a bug where the NumLock is not correctly set to the setting of the host system,
  233.     ; so you have to press the NumLock key twice so that DOSBox recognizes the status.
  234.     ; see: https://sourceforge.net/p/dosbox/bugs/71/
  235.     ;      https://superuser.com/questions/255102/is-there-a-way-to-use-the-numeric-keypad-in-dosbox/1146986
  236.     ; Since the game uses number keys very often, we set NumLock to ON
  237.     call    set_numlock_on
  238.  
  239.     ; Reduce size of own application to give the called applications more space
  240.     ; see https://stackoverflow.com/a/10067627
  241.     mov     ah, 4Ah
  242.     mov     bx, 100       ; 100 paragraphs a 16 bytes = 1600 bytes
  243.     int     21h
  244.  
  245. menu:
  246.     ; Video Mode VGA 12
  247.     call    set_screen12
  248.  
  249.     ; Flush keyboard buffer    
  250.     call    flush_keyb_buf
  251.  
  252.     ; Print menu screen
  253.     call    print_menu_screen
  254.    
  255. retry:
  256.     ; Query keyboard input
  257.     mov     ah, 07h       ; Direct character input, without echo
  258.     int     21h
  259.     cmp     al, '1'
  260.     je      prog1
  261.     cmp     al, '2'
  262.     je      prog2
  263.     cmp     al, '9'
  264.     je      exit
  265.  
  266.     ; Invalid input
  267.     jmp     retry
  268.  
  269. prog1:
  270.     ; Clear screen
  271.     call    clear_vga
  272.  
  273.     ; Setup parameter block for the EXEC command
  274.     call    setup_paramblk
  275.  
  276.     ; Start game 1
  277.     mov     ah, 4Bh       ; execute
  278.     mov     al, 00h       ; load and execute
  279.     mov     bx, paramblk
  280.     lea     dx, exename1
  281.     int     21h
  282.    
  283.     ; Is everything OK? Or is the GAM file missing?
  284.     jc      error
  285.  
  286.     ; Notify the player that the game has finished
  287.     jmp     gameover
  288.  
  289. prog2:
  290.     ; Clear screen
  291.     call    clear_vga
  292.    
  293.     ; Setup parameter block for the EXEC command
  294.     call    setup_paramblk
  295.  
  296.     ; Start game 2
  297.     mov     ah, 4Bh       ; execute
  298.     mov     al, 00h       ; load and execute
  299.     mov     bx, paramblk
  300.     lea     dx, exename2
  301.     int     21h
  302.    
  303.     ; Is everything OK? Or is the GAM file missing?
  304.     jc      error
  305.  
  306.     ; Notify the player that the game has finished
  307.     jmp     gameover
  308.    
  309. error:
  310.     ; Video Mode VGA 12
  311.     call    set_screen12
  312.  
  313.     ; Clear screen
  314.     ; call    clear_vga
  315.    
  316.     ; Print error
  317.     call    print_error_screen
  318.    
  319.     ; Give the player time to read the error message (approx 5 seconds)
  320.     call    sleep_5
  321.  
  322.     ; Go back to the menu
  323.     jmp     menu
  324.    
  325. gameover:
  326.     ; Print gameover screen
  327.     call    print_gameover_screen
  328.  
  329.     ; Give the player time to read the game over message (approx 5 seconds)
  330.     call    sleep_5
  331.  
  332.     ; Go back to the menu
  333.     jmp     menu
  334.    
  335. exit:
  336.     ; Reset video mode to DOS default
  337.     pop     ax            ; the video mode we have preserved at program start
  338.     mov     ah, 0         ; set screen mode
  339.     int     10h
  340.  
  341.     ; Return to DOS
  342.     call    exit_to_dos
  343.  
  344. ; -------------------------------------------------------
  345.  
  346. end start