Skip to content

Instantly share code, notes, and snippets.

@medvecky
Last active September 28, 2023 11:12
Show Gist options
  • Save medvecky/0c5e063f79aa05972b18f4da61e056d8 to your computer and use it in GitHub Desktop.
Save medvecky/0c5e063f79aa05972b18f4da61e056d8 to your computer and use it in GitHub Desktop.
Fractions calculator for Commodore 64 on 6510 assembly KIckAssembler (definitions)
#importonce
#import "subroutines.asm"
.const clearscreen = $e544;
.const print_str = $ab1e;
.const print_char = $ffd2
.const getin = $ffe4
.const text_color = $0286;
.const set_cursor = $e50c;
.const background = $d021;
.const border = $d020;
.const fp_string_to_fac = $b7b5;
.const fp_store_fac_to_ram = $bbd4;
.const fp_fac_print = $aabc;
.const fp_load_ram_to_fac = $bba2;
.const fp_div = $bb0f;
.const fp_int = $bccc;
.const fp_mult = $ba28;
.const fp_subst =$b850;
.const fp_add = $b867;
.const fp_cmp = $bc5b;
.const fp_abs = $bc58;
.const fp_to_str = $bddd;
.var new_line = $8d;
.var q_sym = $51;
.var space_sym = $20;
.var slash_sym = $2f;
.var minus_sym = $2d;
.var zero_sym = $30;
.var one_sym = $31;
.var two_sym = $32;
.var three_sym = $33;
.var four_sym = $34;
.var five_sym = $35;
.var six_sym = $36;
.var seven_sym = $37;
.var eight_sym = $38;
.var nine_sym = $39;
.var string_length = $0F;
.macro print_new_line( number_of_new_lines )
{
lda #new_line
.for( var i = 0; i < number_of_new_lines; i++)
{
jsr print_char
}
}
.macro print_string( string_label )
{
lda #<string_label
ldy #>string_label
jsr print_str
}
.macro set_cursor_x_y( x, y )
{
ldx #x
ldy #y
jsr set_cursor
}
.macro print_char( char )
{
lda #char
jsr print_char
}
.macro input_fp_value( prompt_label, variable_label )
{
print_string( prompt_label )
jsr cursor_blink_on
jsr input_string_proc
jsr string_to_fp
fp_fac_to_ram( variable_label )
print_char( space_sym )
print_new_line( 1 )
}
.macro print_fp_string( source_variable )
{
fp_ram_to_fac( source_variable )
jsr fp_fac_print
}
.macro fp_fac_to_ram( variable_label )
{
ldx #<variable_label
ldy #>variable_label
jsr fp_store_fac_to_ram
}
.macro fp_ram_to_fac( variable_label )
{
lda #<variable_label
ldy #>variable_label
jsr fp_load_ram_to_fac
}
.macro fp_div( divisible_label, divider_label )
{
fp_ram_to_fac( divider_label )
lda #<divisible_label
ldy #>divisible_label
jsr fp_div
}
.macro fp_mult( multiplicand_label, multiplier_label )
{
fp_ram_to_fac( multiplier_label )
lda #<multiplicand_label
ldy #>multiplicand_label
jsr fp_mult
}
.macro fp_subst( minuend_label, subtrahend_label )
{
fp_ram_to_fac( subtrahend_label )
lda #<minuend_label
ldy #>minuend_label
jsr fp_subst
}
.macro fp_add( term1, term2 )
{
fp_ram_to_fac( term1 )
lda #<term2
ldy #>term2
jsr fp_add
}
.macro fp_modulo( dividend_label, divisor_label )
{
//The subroutine calculates modulo by
// the following formula: A % B = A — INT(A / B) * B.
fp_ram_to_fac( dividend_label )
jsr fp_abs
fp_fac_to_ram( dividend_label )
fp_ram_to_fac( divisor_label )
jsr fp_abs
fp_fac_to_ram( divisor_label )
fp_div( dividend_label, divisor_label )
jsr fp_int
lda #<divisor_label
ldy #>divisor_label
jsr fp_mult
lda #<dividend_label
ldy #>dividend_label
jsr fp_subst
}
.macro fp_cmp( variable_label )
{
lda #<variable_label
ldy #>variable_label
jsr fp_cmp
}
.macro print_fp_string_part( source_variable )
{
lda #<source_variable
ldy #>source_variable
jsr fp_load_ram_to_fac
jsr fp_to_str
jsr print_str
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment