<commit_before>
import misc, time
from misc cimport Misc

include "globals.pxi"


cdef class Cmos:
    def __init__(self, object main):
        self.main = main
        self.cmosIndex = 0
    cdef unsigned long readValue(self, unsigned char index, unsigned char size):
        return self.configSpace.csReadValue(index, size, False)
    cdef writeValue(self, unsigned char index, unsigned long value, unsigned char size):
        self.configSpace.csWriteValue(index, value, size)
    cdef reset(self):
        cdef unsigned long long extMemSizeInK
        self.configSpace.csResetData()
        self.writeValue(CMOS_STATUS_REGISTER_B, 0x06, OP_SIZE_BYTE)
        self.writeValue(CMOS_STATUS_REGISTER_D, 0x80, OP_SIZE_BYTE)
        self.writeValue(CMOS_EQUIPMENT_BYTE, 0x21, OP_SIZE_BYTE)
        self.writeValue(CMOS_BASE_MEMORY_L, 0x80, OP_SIZE_BYTE)
        self.writeValue(CMOS_BASE_MEMORY_H, 0x02, OP_SIZE_BYTE)
        extMemSizeInK = (self.main.memSize//1024)-640
        if (extMemSizeInK > 16384): # 16M
            extMemSizeInK = 16384   # 16M
        self.writeValue(CMOS_EXT_MEMORY_L, extMemSizeInK&0xff, OP_SIZE_BYTE)
        self.writeValue(CMOS_EXT_MEMORY_H, (extMemSizeInK>>8)&0xff, OP_SIZE_BYTE)
        self.writeValue(CMOS_EXT_MEMORY_L2, self.readValue(CMOS_EXT_MEMORY_L, OP_SIZE_BYTE), OP_SIZE_BYTE)
        self.writeValue(CMOS_EXT_MEMORY_H2, self.readValue(CMOS_EXT_MEMORY_H, OP_SIZE_BYTE), OP_SIZE_BYTE)
        extMemSizeInK //= 64 # next two lines will need the memSize in 64K-blocks
        self.writeValue(CMOS_EXT_MEMORY2_L, extMemSizeInK&0xff, OP_SIZE_BYTE)
        self.writeValue(CMOS_EXT_MEMORY2_H, (extMemSizeInK>>8)&0xff, OP_SIZE_BYTE)
        self.writeValue(CMOS_EXT_BIOS_CFG, 0x20, OP_SIZE_BYTE) # boot from floppy first.
        ##self.updateTime()
    cdef updateTime(self):
        cdef unsigned char second, minute, hour, mday, wday, month, year, statusb, century
        statusb = self.readValue(CMOS_STATUS_REGISTER_B, OP_SIZE_BYTE)
        self.dt = time.localtime()
        second  = self.dt.tm_sec
        minute  = self.dt.tm_min
        hour    = self.dt.tm_hour
        wday    = self.dt.tm_wday
        mday    = self.dt.tm_mday
        month   = self.dt.tm_mon
        century, year = divmod(self.dt.tm_year, 100)
        if (not statusb&CMOS_STATUSB_24HOUR):
            if (hour >= 12):
                hour %= 12
                if (hour == 0):
                    hour = 12
                hour |= 80
            elif (hour == 0):
                hour = 12
        wday += 2
        wday %= 7
        if (wday == 0):
            wday = 7
        if (not statusb&CMOS_STATUSB_BIN):
            second  = (<Misc>self.main.misc).decToBcd(second)
            minute  = (<Misc>self.main.misc).decToBcd(minute)
            hour    = (<Misc>self.main.misc).decToBcd(hour)
            wday    = (<Misc>self.main.misc).decToBcd(wday)
            mday    = (<Misc>self.main.misc).decToBcd(mday)
            month   = (<Misc>self.main.misc).decToBcd(month)<commit_msg>commit... now, cmos shows the correct amount of physical memory.<commit_after>
import misc, time
from misc cimport Misc

include "globals.pxi"


cdef class Cmos:
    def __init__(self, object main):
        self.main = main
        self.cmosIndex = 0
    cdef unsigned long readValue(self, unsigned char index, unsigned char size):
        return self.configSpace.csReadValue(index, size, False)
    cdef writeValue(self, unsigned char index, unsigned long value, unsigned char size):
        self.configSpace.csWriteValue(index, value, size)
    cdef reset(self):
        cdef unsigned long long memSizeInK, extMemSizeInK, extMemSizeIn64K
        memSizeInK = extMemSizeInK = extMemSizeIn64K = 0
        self.configSpace.csResetData()
        self.writeValue(CMOS_STATUS_REGISTER_B, 0x06, OP_SIZE_BYTE)
        self.writeValue(CMOS_STATUS_REGISTER_D, 0x80, OP_SIZE_BYTE)
        self.writeValue(CMOS_EQUIPMENT_BYTE, 0x21, OP_SIZE_BYTE)
        self.writeValue(CMOS_EXT_BIOS_CFG, 0x20, OP_SIZE_BYTE) # boot from floppy first.
        self.writeValue(CMOS_BASE_MEMORY_L, 0x80, OP_SIZE_BYTE)
        self.writeValue(CMOS_BASE_MEMORY_H, 0x02, OP_SIZE_BYTE)
        memSizeInK = (self.main.memSize//1024)
        if (memSizeInK > 1024): # if we have over 1MB physical memory ...
            extMemSizeInK = (memSizeInK - 1024) # ... extMemSizeInK is all physical memory over 1MB as KB ...
        if (extMemSizeInK > 0xfc00): # ... with an maximal value of 0xfc00 == 63MB extended memory == 64MB physical memory.
            extMemSizeInK = 0xfc00
        self.writeValue(CMOS_EXT_MEMORY_L, extMemSizeInK&0xff, OP_SIZE_BYTE)
        self.writeValue(CMOS_EXT_MEMORY_L2, extMemSizeInK&0xff, OP_SIZE_BYTE)
        self.writeValue(CMOS_EXT_MEMORY_H, (extMemSizeInK>>8)&0xff, OP_SIZE_BYTE)
        self.writeValue(CMOS_EXT_MEMORY_H2, (extMemSizeInK>>8)&0xff, OP_SIZE_BYTE)
        if (memSizeInK > 16384):
            extMemSizeIn64K = ((memSizeInK - 16384) // 64)
        if (extMemSizeIn64K > 0xbf00):
            extMemSizeIn64K = 0xbf00
        self.writeValue(CMOS_EXT_MEMORY2_L, extMemSizeIn64K&0xff, OP_SIZE_BYTE)
        self.writeValue(CMOS_EXT_MEMORY2_H, (extMemSizeIn64K>>8)&0xff, OP_SIZE_BYTE)
        # TODO: set here the physical memory over 4GB if we need it...
        # ... or if we're able to handle it anywhere in the future... oO
        ##self.updateTime()
    cdef updateTime(self):
        cdef unsigned char second, minute, hour, mday, wday, month, year, statusb, century
        statusb = self.readValue(CMOS_STATUS_REGISTER_B, OP_SIZE_BYTE)
        self.dt = time.localtime()
        second  = self.dt.tm_sec
        minute  = self.dt.tm_min
        hour    = self.dt.tm_hour
        wday    = self.dt.tm_wday
        mday    = self.dt.tm_mday
        month   = self.dt.tm_mon
        century, year = divmod(self.dt.tm_year, 100)
        if (not statusb&CMOS_STATUSB_24HOUR):
            if (hour >= 12):
                hour %= 12
                if (hour == 0):
                    hour = 12
                hour |= 80
            elif (hour == 0):
                hour = 12
        wday += 2
        wday %= 7
        if (wday == 0):
            wday = 7
        if (not statusb&CMOS_STATUSB_BIN):
            second  = (<Misc>self.main.misc).decToBcd(second)
            minute  = (<Misc>self.main.misc).decToBcd(minute)
            hour    = (<Misc>self.main.misc).decToBcd(hour)
            wday    = (<Misc>self.main.misc).decToBcd(wday)
            mday    = (<Misc>self.main.misc).decToBcd(mday)
            month   = (<Misc>self.main.misc).decToBcd(month)
{'fraction_non_alphanumeric': 0.09918107370336669, 'fraction_numerical': 0.028662420382165606, 'mean_word_length': 2.480211081794195, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 32, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4449379', 'n_tokens_mistral': 2464, 'n_tokens_neox': 2285, 'n_words': 467}