initial upload

This commit is contained in:
Luxferre
2025-05-04 11:46:54 +03:00
commit 5810c2f985
22 changed files with 2146 additions and 0 deletions
+8
View File
@@ -0,0 +1,8 @@
8401409
6308099
12632321
12599169
12714113
12616065
12697729
6291585
+3
View File
@@ -0,0 +1,3 @@
8389899
6340746
6324363
+30
View File
@@ -0,0 +1,30 @@
8397628
8402109
8397118
8403647
8404288
8389953
8388609
12599169
8388994
12648578
8389251
12648579
8388741
2179346
6331965
6332480
6332480
8388613
2179479
6332223
6332480
6332480
8388613
2097818
6291585
2195483
6332609
8401412
12599428
2130439
+11
View File
@@ -0,0 +1,11 @@
8397825
8401538
8402435
8402436
8402821
8403206
8402439
8401416
8392841
8389898
6324362
+49
View File
@@ -0,0 +1,49 @@
8388618
8388619
8388620
8388621
8388622
8388623
6307970
8405123
12616067
8405252
12616196
8405253
12615813
12583050
12583179
12583308
12583437
12583566
12599183
12583427
2113926
12599055
8406918
12617478
8406407
12616967
12600071
8406918
12617222
8406280
12616712
12600072
8406033
12632977
8406278
12617862
12600710
8406928
12632848
8406406
12617094
8406913
12617345
12599430
8406017
12616449
12681362
12632978
6293522
+79
View File
@@ -0,0 +1,79 @@
8395905
8421377
12599041
2113665
8389940
8391861
10487861
11708470
8394423
10486199
10960952
10800936
8401465
12623016
10749097
11673130
11212318
11393951
11575584
11757217
11938850
8397220
10489124
8397989
10486949
8394406
10486310
8394407
10485799
6296618
8388610
2168098
6308098
12622722
8410371
12589827
8405252
12599684
12632452
12714497
12622849
12604545
12589697
8405161
12622337
12604417
8405160
12604674
8405290
2118963
8388650
2118709
8388648
8411649
12604417
2113693
6296618
8409985
12604545
2113726
6295842
2195534
8409857
12604545
2113731
6295713
2195534
8409729
12604545
2113736
6295584
2195534
8409601
12604545
2113741
6295455
2195534
6295326
0
+66
View File
@@ -0,0 +1,66 @@
8389898
8388668
8388797
8388926
8389055
8389184
8389313
8389442
8389571
8389700
8389829
8396358
8398919
8389902
10485774
8389131
8389761
14680193
12591873
8388866
8454274
8389891
12599555
2097552
8422657
8406401
12592001
8388867
8454529
12599051
2114960
8389515
6319582
8400198
8388628
8389132
8389133
8406529
8414082
12583042
8406657
8413955
12583043
8388737
8454401
8389124
8454532
12599809
2179255
8406658
12600834
2179382
12599188
2195511
12584724
12599053
2115237
12599052
2115108
6294036
8389121
12601857
2097345
12599051
2114976
6301908
+117
View File
@@ -0,0 +1,117 @@
8389299
8390324
8393270
8401461
8388668
10649660
2195491
16767489
8389890
12632194
8388611
12648707
12615555
12615811
2113937
8389891
2310269
12599043
2179476
12589699
12599171
2310269
8402946
12599426
8405251
12589571
12616066
12665091
12632450
12599042
12622210
12599426
8411779
12648707
2310269
6331190
6299196
2170484
6315709
8412801
12606977
2130164
8405180
2326535
8405438
8405380
2326535
12583358
8412929
2326550
8391297
12599681
2097315
2326535
8405439
2326535
12583359
8402817
12607361
2097390
6291972
8388672
8388673
6299583
6308485
2097873
12599045
2097869
12599045
2097863
2195539
2187347
8412801
12606977
8405180
12590781
8388801
2326535
12583359
12599232
2195539
8388801
12599232
8413057
2326550
8391297
12599681
2162906
6299583
2195491
2105535
8405383
8412929
2326550
8405382
8390657
12599681
2113765
2326535
12583358
2195548
6299455
8405889
12600065
2097394
2130161
8391297
12600065
2113777
2195491
8388865
12639873
12583100
12590780
12590780
2195491
0
+12
View File
@@ -0,0 +1,12 @@
; A simple compound interest calculator in N8A for n808 VM
; Prompts for the percentage and then for the period, outputs the resulting multiplier
; Created by Luxferre in 2025, released into public domain
dca 100 1 ; store the constant 100 at loc 1
inp 2 3 ; prompt for the percentage into loc 2 and the period into loc 3
div 2 1 ; divide the percentage value at loc 2 by the constant at loc 1 into loc 1
inc 1 ; increment loc 1
log 1 1 ; replace loc 1 with its ln
mul 3 1 ; replace loc 1 with loc 3 * ln loc 1
exp 1 1 ; replace loc 1 with its nexp
out 1 1 ; output the resulting value
+5
View File
@@ -0,0 +1,5 @@
; Simple 10-character echo test for n808 VM
dca 10 11 ; set the newline character to loc 11
ipc 1 10 ; input characters from loc 1 to loc 10
ouc 1 11 ; output them right away along with the newline
+39
View File
@@ -0,0 +1,39 @@
; FizzBuzz classical challenge in N8A for n808 VM
; Outputs first 100 FizzBuzz numbers
; Created by Luxferre in 2025, released into public domain
dca 70 60 ; store Fi into loc 60-61
dca 105 61
dca 66 62 ; store Buz + LF into loc 62-65
dca 117 63
dca 122 64
dca 10 65
#1 cntr ; counter in loc 1
#2 cmod3 ; variable for counter mod 3
#3 cmod5 ; variable for counter mod 5
#4 chk ; variable for loop checks
#5 oflag ; normal output flag variable
dca 0 @cntr ; set counter to 0
:lp inc @cntr ; loop start, increment the counter
dca 3 @cmod3 ; store constant 3
mdf @cntr @cmod3 ; store counter mod 3
dca 5 @cmod5 ; store constant 5
mdf @cntr @cmod5 ; store counter mod 5
dca 1 @oflag ; set normal output flag
jne @cmod3 :bu ; jump next if not divisible by 3
ouc 60 61 ; output Fizz sequence
ouc 64 64
ouc 64 64
dca 0 @oflag ; unset normal output flag
:bu jne @cmod5 :no ; jump next if not divisible by 5
ouc 62 63 ; output Buzz sequence
ouc 64 64
ouc 64 64
dca 0 @oflag ; unset normal output flag
:no jeq @oflag :nl ; jump next if normal output flag is off
out @cntr @cntr ; normal counter output
juc :le ; jump to the end of the loop
:nl ouc 65 65 ; output a newline
:le dca 100 @chk ; store the constant 100 into checkvar
sub @cntr @chk ; save the difference into checkvar
jlt @chk :lp ; go back in the loop if not every number is displayed yet
+11
View File
@@ -0,0 +1,11 @@
dca 72 1 ; fill in the data bytes from 1 to 10
dca 101 2
dca 108 3
dca 108 4
dca 111 5
dca 114 6
dca 108 7
dca 100 8
dca 33 9
dca 10 10 ; end the string with an LF character for newline
ouc 1 10 ; output the range as ASCII to port 2
+77
View File
@@ -0,0 +1,77 @@
; Linear regression calculator in N8A for n808 VM
; Enter the pairs number by number, end with 0,0 pair
; The program will then output A and B parameters of A + Bx
; linear function and then the correlation coefficient r
; Created by Luxferre in 2025, released into public domain
; variable/constant definitions
#1 xi ; data x component
#2 yi ; data y component
#3 xs ; xi squared
#4 ys ; yi squared
#5 xy ; xy
#6 buf ; buffer
#7 r1 ; r-coefficient buffer 1
#8 r2 ; r-coefficient buffer 2
#10 Sxi ; x sum
#11 Syi ; y sum
#12 Sxx ; x squared sum
#13 Syy ; y squared sum
#14 Sxy ; xy sum
#15 n ; data element counter
#16 A ; coefficient A
#17 B ; coefficient B
#18 RC ; coefficient R
; zero out all sums
dca 0 @Sxi
dca 0 @Syi
dca 0 @Sxx
dca 0 @Syy
dca 0 @Sxy
dca 0 @n
; data input loop
:lp inp @xi @yi ; loop start, input xi and yi pair
dva @xi @xs ; prepare x
mul @xs @xs ; square x
dva @yi @ys ; prepare y
mul @ys @ys ; square y
dva @yi @xy ; prepare y
mul @xi @xy ; save xy
add @xi @Sxi ; update x sum
add @yi @Syi ; update y sum
add @xs @Sxx ; update x squared sum
add @ys @Syy ; update y squared sum
add @xy @Sxy ; update xy sum
inc @n ; increment element count
add @ys @xs ; add y-squared to x-squared
jgt @xs :lp ; loop back if the square sum is over zero
dec @n ; decrement last n to omit the (0,0) input
; processing and output part
dva @n @buf ; n => buffer
mul @Sxy @buf ; n * Sxy => buffer
dva @Syi @r1 ; Syi => r-buffer 1
mul @Sxi @r1 ; Sxi * Syi => r-buffer 1
sub @buf @r1 ; n * Sxy - Sxi * Syi => r-buffer 1 (to be stored)
dva @n @buf ; n => buffer
mul @Sxx @buf ; n * Sxx => buffer
dva @Sxi @r2 ; Sxi => r-buffer 2
mul @r2 @r2 ; Sxi squared => r-buffer 2
sub @buf @r2 ; n * Sxx - Sx^2 => r-buffer 2 (to be stored)
dva @r2 @B ; prepare coefficient B
div @r1 @B ; store coefficient B
dva @Sxi @buf ; copy Sxi to buffer
mul @B @buf ; B * Sxi => buffer
sub @Syi @buf ; Syi - B * Sxi => buffer
dva @n @A ; prepare coefficient A
div @buf @A ; calculate coefficient A
dva @Syi @buf ; Syi => buffer
mul @Syi @buf ; Syi squared => buffer
dva @n @xi ; reuse xi for the second buffer
mul @Syy @xi ; n * Syy => second buffer
sub @xi @buf ; n * Syy - Sy^2 => buffer
dva @r2 @xi ; r-buffer 2 to xi
mul @buf @xi ; buffer * xi => xi
sqr @xi @RC ; sqrt(xi) => prepare RC
div @r1 @RC ; calculate correlation coefficient
out @A @RC ; output all three resulting numbers
+131
View File
@@ -0,0 +1,131 @@
; Lunar Lander game in N8A for n808 VM
; On each turn, the following parameters are displayed in this order:
; altitude (meters), speed (m/s) and remaining fuel (kg)
; Your goal is to apply (or not apply) thrust
; (values that make any sense are 0 to 2000) every 10 seconds of flight
; and get the lunar module to land safely without running out of fuel.
; At the end, the game shows one of the following statuses:
; 4444 is a disaster landing with no survivors,
; 5555 is a crash landing with the crew surviving the impact,
; 6666 is a hard landing with some damage to the pod,
; 7777 is a good landing,
; 8888 is a perfect landing.
; Created by Luxferre in 2025, released into public domain
; constant/variable area
#30 code_dis ; disaster code
#31 code_crsh ; crash landing code
#32 code_dmg ; damage landing code
#33 code_good ; good landing code
#34 code_perf ; perfect landing code
#36 crit_crsh ; criterion for crash landing
#37 crit_dmg ; criterion for damage landing
#38 crit_good ; criterion for good landing
#39 crit_perf ; criterion for perfect landing
#40 alt ; module altitude
#41 speed ; module fall speed (m/s)
#42 fuel ; fuel (in kg)
#52 athr ; altitude threshold AND time period
#53 ffsd ; freefall speed delta
#54 capw ; capsule weight (in kg)
#55 burnrate ; fuel burn rate
#56 exvel ; exhaust velocity
#57 c100 ; constant 100
#1 buf ; buffer variable
#2 floss ; fuel loss value
#3 m0 ; m0 variable in the equation
#4 m1 ; m1 variable in the equation
; memory initialization part
; zero out the memory (first 57 cells)
dca 57 1 ; set the counter to 57
:clp ica 0 1 ; assign 0 to the cell from the counter
dec 1
jgt 1 :clp
; set constants and initial variable values
dca 10 @athr ; altitude threshold / time period
dca 25 @ffsd ; set 16.25 as freefall speed delta
set 0 16 @ffsd
set 74 80 @capw ; set 7480 as capsule weight
dca 45 @burnrate ; set 3.45 as fuel burn rate
set 0 3 @burnrate
set 29 0 @exvel ; set 2900 as exhaust velocity
set 19 30 @alt ; set 1930 as starting altitude
dca 100 @c100 ; set constant 100
mul @c100 @alt ; multiply this altitude value by 100
set 16 9 @speed ; set 1609 as starting speed
set 72 60 @fuel ; set 7260 as fuel
set 44 44 @code_dis ; set 4444 as disaster code
set 55 55 @code_crsh ; set 5555 as crash landing code
set 66 66 @code_dmg ; set 6666 as damage landing code
set 77 77 @code_good ; set 7777 as good landing code
set 88 88 @code_perf ; set 8888 as perfect landing code
dca 67 @crit_crsh ; set 26.67 as the criterion for crash landing
set 0 26 @crit_crsh
dca 73 @crit_dmg ; set 9.73 as the criterion for damage landing
set 0 9 @crit_dmg
dca 45 @crit_good ; set 4.45 as the criterion for good landing
set 0 4 @crit_good
dca 45 @crit_perf ; set 0.45 as the criterion for perfect landing
set 0 0 @crit_perf
; main action/logic part
:lp out @alt @fuel ; loop start; print altitude, speed and fuel
dca 0 @floss ; set fuel loss to 0
jle @fuel :cnt ; skip prompting for thrust if already out of fuel
inp @floss @floss ; prompt for thrust into the fuel loss location
mul @burnrate @floss ; multiply thrust by fuel burn rate to get fuel loss
:cnt dva @fuel @m0 ; copy fuel weight into m0
add @capw @m0 ; add capsule weight and fuel weight to get m0
dva @floss @m1 ; prepare m1
sub @m0 @m1 ; m0 - floss => m1
div @m0 @m1 ; m0 / m1 => m1
log @m1 @buf ; ln (m0 / (m0 - floss)) => buf
mul @exvel @buf ; multiply the result by the exhaust velocity to get thrust speed delta
sub @speed @buf ; subtract the thrust speed delta from the current speed
add @ffsd @buf ; add the freefall speed delta to the current speed
dva @buf @speed ; copy the resulting speed value back to the holding variable
mul @athr @buf ; multiply speed by time period into the buffer variable
sub @alt @buf ; decrease the altitude by the result of this operation
dva @buf @alt ; restore the altitude variable
sub @fuel @floss ; decrease the amount of fuel by the fuel loss value
dva @floss @fuel ; restore the fuel variable
jgt @fuel :flc ; skip the next instruction if the amount of fuel is positive
dca 0 @fuel ; just set the amount of fuel to zero if it's negative
:flc jgt @alt :al ; do the same for altitude
dca 0 @alt ; set it to zero if negative
:al dva @athr @buf ; copy altitude threshold to the buffer
sub @alt @buf ; subtract the threshold from the altitude
jgt @buf :lp ; go to the loop start if the altitude is above the threshold
; game finalization/scoring part
out @alt @fuel ; print the final altitude/speed/fuel
dva @crit_perf @buf ; buffer the perfect speed
sub @speed @buf ; subtract the perfect speed
jgt @buf :good ; skip if > 0
out @code_perf @code_perf ; output the perfect score
juc :end ; go to end
:good dva @crit_good @buf ; buffer the good speed
sub @speed @buf ; subtract the good speed
jgt @buf :dmg ; skip if > 0
out @code_good @code_good ; output the good score
juc :end ; go to end
:dmg dva @crit_dmg @buf ; buffer the damage speed
sub @speed @buf ; subtract the damage speed
jgt @buf :crsh ; skip if > 0
out @code_dmg @code_dmg ; output the damage score
juc :end ; go to end
:crsh dva @crit_crsh @buf ; buffer the crash speed
sub @speed @buf ; subtract the crash speed
jgt @buf :disa ; skip if > 0
out @code_crsh @code_crsh ; output the crash score
juc :end ; go to end
:disa out @code_dis @code_dis ; output the disaster score
:end nnn ; program end label
+108
View File
@@ -0,0 +1,108 @@
; Bulls and Cows game in N8A for n808 VM
; Enter your guesses digit by digit, you have 7 attempts
; After each guess, the game replies with bulls.cows
; (if you have 4.0, you win)
; On victory or after running out of attempts, the game
; displays the target digits and halts
; Created by Luxferre in 2025, released into public domain
; constants/variables section
#1 va
#2 vb
#3 vc
#4 vd
#10 c10
#11 counter
#12 octr
#13 ictr
#14 frac
#20 bcctr
#60 dig_0
#61 dig_1
#62 dig_2
#63 dig_3
#64 dig_4
#65 dig_5
#66 dig_6
#67 dig_7
#68 dig_8
#69 dig_9
#70 src_base ; source base address
#71 trg_base ; target base address
; constant/variable assignments
dca 10 @c10 ; constant 10
dca 0 @dig_0 ; assign digits from 0 to 9
dca 1 @dig_1
dca 2 @dig_2
dca 3 @dig_3
dca 4 @dig_4
dca 5 @dig_5
dca 6 @dig_6
dca 7 @dig_7
dca 8 @dig_8
dca 9 @dig_9
dca 60 @src_base ; set the source base address (60)
dca 80 @trg_base ; set the target base address (80)
dca 10 @frac ; prepare the @frac variable
set 0 0 @frac ; set 0.1 to @frac
; main logic
; random unique 4-digit generator (into the addresses 81..84)
dca 4 @counter ; set the counter to 4
:dsl dca 9 @va ; digit selection loop start, set the upper boundary to @va
rnd 0 @va @va ; select a random digit from 0 to 9 inclusively into @va
add @src_base @va ; add the source base address to @va
dca @vb @vb ; init @vb with its own address
ivc @va @vb ; copy the value at address in @va into @vb
dca 10 @vc ; init @vc with the constant 10
sub @vb @vc ; @vb - 10 => @vc
jeq @vc :dsl ; jump back to the digit selection if the value at @vc is 0
ica 10 @va ; set the value at the address in @va to 10
dva @counter @va ; copy the counter to @va
add @trg_base @va ; add the target base address to the counter in @va
dca @vb @vc ; copy the address of @vb into @vc
ivc @vc @va ; copy the value from @vb (address stored at @vc) to the cell address at @va
dec @counter ; decrement the counter
jgt @counter :dsl ; jump back to digit selection if it still is above zero
; player guess loop
dca 7 @counter ; set the attempt count to 7
:prm inp 91 94 ; input the guess digit by digit into loc 91..94
dca 90 @src_base ; set 90 as the new source base address
dca 0 @bcctr ; init bull/cow counter
dca 4 @octr ; init outer loop counter
:olp dca 4 @ictr ; start of the outer loop, init inner loop counter
:ilp dva @octr @va ; start of the inner loop, copy the outer counter
dva @trg_base @vb ; fetch the target base address
add @va @vb ; get the address of the target digit in @vb
dva @ictr @va ; copy the inner counter
dva @src_base @vc ; fetch the source base address
add @va @vc ; get the address of the entered digit in @vc
dca @va @va ; init @va with its own address
ivc @vb @va ; copy the target digit into @va
dca @vd @vd ; init @vd with its own address
ivc @vc @vd ; copy the entered digit into @vd
sub @vd @va ; save the digits difference into @va
jne @va :ei ; jump to the next comparator if the digits don't match
dva @ictr @vb ; load the inner counter into @vb
sub @octr @vb ; save the _counters_ difference into @vb
jne @vb :cc ; jump to the cow counter if the indices don't match
inc @bcctr ; increment the bull counter if they do
juc :ei ; skip the next instruction
:cc add @frac @bcctr ; increase the cow counter if they don't
:ei dec @ictr ; decrement the inner loop counter
jgt @ictr :ilp ; jump to the start of the inner loop if still > 0
dec @octr ; decrement the outer loop counter
jgt @octr :olp ; jump to the start of the outer loop if still > 0
out @bcctr @bcctr ; output the match result
dca 4 @va ; store the constant 4 into @va
sub @bcctr @va ; get the difference between bull/cow counter and 4
jeq @va :end ; jump to the last instruction if they match
dec @counter ; decrement the attempt counter
jgt @counter :prm ; jump to guess prompt if the counter is above 0
:end out 81 84 ; output the target number before halting
+166
View File
@@ -0,0 +1,166 @@
; A Blackjack port in N8A assembly for n808 VM
; How to play:
; * you start with a $1000 balance
; * on each round, enter your bet
; (the game will quit if the bet is above your balance)
; * if you hit a blackjack, your balance will increase immediately
; * if the dealer hits a blackjack, your balance will decrease immediately
; * the first card of the dealer's hand will be shown
; (card values are: ace is 101, 2 to 9 are "as is", 10 is 10 to K)
; * on the first turn, select 0 (stand), 1 (hit) or 2 (double)
; * on each next turn, select 0 (stand) or 1 (hit)
; * as a result of the round, the dealer's final hand will be shown
; first and then yours
; * the dealer must draw on 16 and stand on any 17
; * player's blackjack pays 3 to 2
; Created by Luxferre in 2025, released into public domain
; constant/variable space
#1 va
#2 vb
#3 vc
#4 vd
#5 action
#6 dscore
#7 pscore
#127 c1
#51 c5
#52 c_13
#53 c_hund
#54 c_ds
#60 balance
#61 bet
#62 dhand
#63 phand
#64 round
#65 stand
; constant assignments
dca 5 @c5
dca 13 @c_13
dca 36 @c_ds
dca 100 @c_hund
dca 0 @balance
set 10 0 @balance
juc :main ; jump to the main code after initialization
; card retrieval procedure
; the resulting card is in the @vc cell
:gcard rnd @c1 @c_13 @va ; get a random number from 1 to 13 incl
dca 10 @vb ; assign 10 to the second buffer
div @va @vb ; va / 10 => vb
dca 0 @vc ; 0 => vc
mdf @vb @vc ; floor(va/10) => vc
sub @c1 @vc ; subtract it from 1
mul @va @vc ; multiply it by the random choice itself
jgt @vc :gnext ; skip the next part if > 0
dca 10 @vc ; return 10
ret
:gnext dec @vc ; decrement
jne @vc :gnr ; skip the next part if == 0
add @c_hund @vc ; add 100
:gnr inc @vc ; increment back
ret
; scoring procedure, parameter is in the @va cell
; the result is in the @vc cell
:score dca 112 @vb ; set vb to 112
sub @va @vb ; set vb to va - 112
dva @vb @vc ; copy vb value into vc
add @c_13 @vc ; add 13 to vc
mul @vc @vb ; vb * vc => vb
abs @vb @vc ; abs(vb) => vc
div @vc @vb ; abs(vb) / vb => vb
dec @vb ; vb - 1 => vb
mul @c5 @vb ; vb * 5 => vb
sub @va @vb ; va - vb => vb
dva @c_hund @vc ; store 100 into vc
mdf @vb @vc ; store vb mod 100 into vc
ret
; main code part
:main ouc @c_ds @c_ds ; output a dollar sign if supported
out @balance @balance ; output the current balance
jle @balance :end ; game over if zero or less
inp @bet @bet ; input your bet
dva @bet @va ; buffer the bet
sub @balance @va ; va = balance - bet
jlt @va :end ; game over if the bet is invalid
dva @va @balance ; restore the balance value from va
jpr :gcard ; call the card generation procedure
dva @vc @dhand ; copy the result as the dealer's hand value
dva @vc @vd ; copy the first dealer hand card into vd
jpr :gcard ; call the card generation procedure again
add @vc @dhand ; complete the dealer's hand
dva @dhand @va ; copy the dealer's hand as the va param
jpr :score ; run the scoring procedure (result in @vc)
dca 21 @va ; set the constant 21 to @va
sub @vc @va ; compare the procedure result with 21
jeq @va :main ; loop back if we have the dealer's blackjack
jpr :gcard ; call the card generation procedure
dva @vc @phand ; save the first card into the player's hand
jpr :gcard ; call the card generation procedure
add @vc @phand ; add the second card into the player's hand
dca 111 @va ; prepare constant 111
sub @phand @va ; compare player's hand to 111
jeq @va :bjk ; jump to blackjack condition on player's blackjack
out @vd @vd ; display the start of the dealer's hand
dca 0 @round ; set the round index to 0
dca 0 @stand ; set the stand flag to 0
:rnl out @phand @phand ; start of the inner player loop, display the player's hand
inp @action @action ; input the action value
jeq @action :std ; jump to stand action if 0
dec @action ; check if 1
jeq @action :hit ; jump to hit action if 1
dec @action ; check if 2
jeq @action :dbl ; jump to double action if 2
juc :skp ; skip otherwise
:dbl jne @round :skp ; skip double if not the first round
dva @bet @va ; buffer the bet
sub @balance @va ; subtract more balance
dva @va @balance ; restore the variable
add @bet @bet ; double the bet
dca 1 @stand ; set the stand flag, proceed to the hit section
:hit jpr :gcard ; generate a new card in @vc
add @vc @phand ; add it to the player's hand
inc @round ; increment the round index
juc :skp ; jump to skip the rest
:std dca 1 @stand ; just set the stand flag
inc @round ; increment the round index
:skp dva @phand @va ; set the player's hand as a parameter to @va
jpr :score ; call the scoring procedure (result in @vc)
dca 21 @va ; set 21 to va
sub @vc @va ; subtract 21 from the result
jle @va :nob ; reloop to beginning if the player is bust
out @phand @phand ; output the player's hand
juc :main ; reloop
:nob jeq @stand :rnl ; repeat the inner loop if the stand flag is 0
dva @vc @pscore ; at this point, player score is now in @vc
:rdl dva @dhand @va ; start the inner dealer loop, set the dealer hand param
jpr :score ; call the scoring procedure (result in @vc)
dva @vc @dscore ; save the dealer's score
dca 16 @va ; compare @vc with 16
sub @vc @va ; the difference is in @va
jgt @va :dbrk ; go to stand if the difference is over 16
jpr :gcard ; call the card generation procedure
add @vc @dhand ; add the result to dealer's hand
juc :rdl ; repeat the inner dealer loop
:dbrk out @dhand @phand ; output both hands (dealer's first)
dva @pscore @va ; buffer the player's score
sub @dscore @va ; subtract it from the dealer's score
jeq @va :push ; push condition
jlt @va :win ; player win condition
dca 21 @va ; prepare constant 21
sub @dscore @va ; compare dealer's score with 21
jgt @va :win ; player win condition
juc :main ; reloop to beginning
:bjk dca 2 @va ; set 2 to @va
div @bet @va ; halve the bet
add @va @balance ; add half the bet to the balance
:win add @bet @balance ; add the bet the first time
:push add @bet @balance ; add the bet the second time
juc :main ; reloop to beginning
:end nnn ; program end label